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
listlengths 0
2
| mutual_with
listlengths 0
11
| ideal_premises
listlengths 0
236
| proof_features
listlengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Vale.Arch.Types.fst | Vale.Arch.Types.lemma_hi64_properties | val lemma_hi64_properties (_:unit) : Lemma
(forall (q0 q1:quad32).{:pattern hi64 q0; hi64 q1}
(q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) | val lemma_hi64_properties (_:unit) : Lemma
(forall (q0 q1:quad32).{:pattern hi64 q0; hi64 q1}
(q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) | let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 193,
"start_col": 0,
"start_line": 181
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
forall (q0: Vale.Def.Types_s.quad32) (q1: Vale.Def.Types_s.quad32).
{:pattern Vale.Arch.Types.hi64 q0; Vale.Arch.Types.hi64 q1}
Mkfour?.hi2 q0 == Mkfour?.hi2 q1 /\ Mkfour?.hi3 q0 == Mkfour?.hi3 q1 <==>
Vale.Arch.Types.hi64 q0 == Vale.Arch.Types.hi64 q1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.forall_intro_2",
"Vale.Def.Types_s.quad32",
"Prims.l_iff",
"Prims.l_and",
"Prims.eq2",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Words_s.nat64",
"Vale.Arch.Types.hi64",
"Prims.l_True",
"Prims.squash",
"Vale.Def.Words_s.nat32",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Vale.Def.Words.Two.nat_to_two_to_nat",
"Vale.Def.Words_s.two",
"Vale.Def.Words.Two_s.two_select",
"Vale.Def.Words.Four_s.four_to_two_two",
"Vale.Arch.Types.hi64_reveal",
"Prims.l_Forall"
] | [] | false | false | true | false | false | let lemma_hi64_properties (_: unit)
: Lemma
(forall (q0: quad32) (q1: quad32).
(q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
| hi64_reveal ();
let helper (q0 q1: quad32)
: Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
() | false |
Spec.Agile.DH.fst | Spec.Agile.DH.dh | val dh: a:algorithm -> s:scalar a -> p:serialized_point a -> Tot (option (serialized_point a)) | val dh: a:algorithm -> s:scalar a -> p:serialized_point a -> Tot (option (serialized_point a)) | let dh a s p =
match a with
| DH_Curve25519 ->
let output = Spec.Curve25519.scalarmult s p in
let is_valid = not (lbytes_eq (create (size_public a) (u8 0)) output) in
if is_valid then Some output else None
| DH_P256 ->
Spec.P256.ecdh p s | {
"file_name": "specs/Spec.Agile.DH.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 56,
"start_col": 0,
"start_line": 49
} | module Spec.Agile.DH
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Lib.ByteSequence
/// Constants
type algorithm =
| DH_Curve25519
| DH_P256
inline_for_extraction
let size_key (a:algorithm) : Tot size_nat =
match a with
| DH_Curve25519 -> 32
| DH_P256 -> 32
inline_for_extraction
let size_public (a:algorithm) : Tot size_nat =
match a with
| DH_Curve25519 -> 32
| DH_P256 -> 64
inline_for_extraction
let prime (a:algorithm) =
match a with
| DH_Curve25519 -> Spec.Curve25519.prime
| DH_P256 -> Spec.P256.prime
/// Types
type scalar (a:algorithm) = lbytes (size_key a)
type serialized_point (a:algorithm) = lbytes (size_public a)
/// Functions
val clamp: alg:algorithm{alg = DH_Curve25519} -> scalar alg -> Tot (scalar alg)
let clamp a k =
match a with
| DH.DH_Curve25519 -> Spec.Curve25519.decodeScalar k
#set-options "--z3rlimit 50" | {
"checked_file": "/",
"dependencies": [
"Spec.P256.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Spec.Agile.DH.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Spec.Agile.DH.algorithm -> s: Spec.Agile.DH.scalar a -> p: Spec.Agile.DH.serialized_point a
-> FStar.Pervasives.Native.option (Spec.Agile.DH.serialized_point a) | Prims.Tot | [
"total"
] | [] | [
"Spec.Agile.DH.algorithm",
"Spec.Agile.DH.scalar",
"Spec.Agile.DH.serialized_point",
"FStar.Pervasives.Native.Some",
"Prims.bool",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"Prims.op_Negation",
"Lib.ByteSequence.lbytes_eq",
"Spec.Agile.DH.size_public",
"Lib.Sequence.create",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.u8",
"Spec.Curve25519.serialized_point",
"Spec.Curve25519.scalarmult",
"Spec.P256.ecdh"
] | [] | false | false | false | false | false | let dh a s p =
| match a with
| DH_Curve25519 ->
let output = Spec.Curve25519.scalarmult s p in
let is_valid = not (lbytes_eq (create (size_public a) (u8 0)) output) in
if is_valid then Some output else None
| DH_P256 -> Spec.P256.ecdh p s | false |
Hacl.Streaming.Poly1305_32.fsti | Hacl.Streaming.Poly1305_32.free | val free : Hacl.Streaming.Functor.free_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M32)
(FStar.Ghost.reveal (FStar.Ghost.hide ()))
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M32)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | let free = F.free (poly1305 M32) (G.hide ()) (t M32) (poly1305_key.I.s ()) | {
"file_name": "code/streaming/Hacl.Streaming.Poly1305_32.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 74,
"end_line": 22,
"start_col": 0,
"start_line": 22
} | module Hacl.Streaming.Poly1305_32
module G = FStar.Ghost
module F = Hacl.Streaming.Functor
module I = Hacl.Streaming.Interface
open Hacl.Impl.Poly1305.Fields
open Hacl.Streaming.Poly1305
#set-options "--fuel 0 --ifuel 0 --z3rlimit 100"
/// Type abbreviation - makes KaRaMeL use pretty names in the generated code
let state_t = F.state_s (poly1305 M32) () (t M32) (poly1305_key.I.s ())
noextract
let alloca = F.alloca (poly1305 M32) () (t M32) (poly1305_key.I.s ())
let malloc = F.malloc (poly1305 M32) () (t M32) (poly1305_key.I.s ())
let reset = F.reset (poly1305 M32) (G.hide ()) (t M32) (poly1305_key.I.s ())
[@@ Comment "0 = success, 1 = max length exceeded" ]
let update = F.update (poly1305 M32) (G.hide ()) (t M32) (poly1305_key.I.s ()) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Streaming.Poly1305.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Poly1305_32.fsti"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Interface",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Streaming.Functor.free_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M32)
(FStar.Ghost.reveal (FStar.Ghost.hide ()))
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M32)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.free",
"Prims.unit",
"Hacl.Streaming.Poly1305.poly1305",
"Hacl.Impl.Poly1305.Fields.M32",
"FStar.Ghost.hide",
"Hacl.Streaming.Poly1305.t",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.Poly1305.poly1305_key"
] | [] | false | false | false | false | false | let free =
| F.free (poly1305 M32) (G.hide ()) (t M32) (poly1305_key.I.s ()) | false |
|
Hacl.Streaming.Poly1305_32.fsti | Hacl.Streaming.Poly1305_32.update | val update : Hacl.Streaming.Functor.update_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M32)
(FStar.Ghost.reveal (FStar.Ghost.hide ()))
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M32)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | let update = F.update (poly1305 M32) (G.hide ()) (t M32) (poly1305_key.I.s ()) | {
"file_name": "code/streaming/Hacl.Streaming.Poly1305_32.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 20,
"start_col": 0,
"start_line": 20
} | module Hacl.Streaming.Poly1305_32
module G = FStar.Ghost
module F = Hacl.Streaming.Functor
module I = Hacl.Streaming.Interface
open Hacl.Impl.Poly1305.Fields
open Hacl.Streaming.Poly1305
#set-options "--fuel 0 --ifuel 0 --z3rlimit 100"
/// Type abbreviation - makes KaRaMeL use pretty names in the generated code
let state_t = F.state_s (poly1305 M32) () (t M32) (poly1305_key.I.s ())
noextract
let alloca = F.alloca (poly1305 M32) () (t M32) (poly1305_key.I.s ())
let malloc = F.malloc (poly1305 M32) () (t M32) (poly1305_key.I.s ())
let reset = F.reset (poly1305 M32) (G.hide ()) (t M32) (poly1305_key.I.s ()) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Streaming.Poly1305.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Poly1305_32.fsti"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Interface",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Streaming.Functor.update_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M32)
(FStar.Ghost.reveal (FStar.Ghost.hide ()))
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M32)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.update",
"Prims.unit",
"Hacl.Streaming.Poly1305.poly1305",
"Hacl.Impl.Poly1305.Fields.M32",
"FStar.Ghost.hide",
"Hacl.Streaming.Poly1305.t",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.Poly1305.poly1305_key"
] | [] | false | false | false | false | false | let update =
| F.update (poly1305 M32) (G.hide ()) (t M32) (poly1305_key.I.s ()) | false |
|
Hacl.Streaming.Poly1305_32.fsti | Hacl.Streaming.Poly1305_32.digest | val digest : Hacl.Streaming.Functor.digest_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M32)
()
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M32)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | let digest = F.digest (poly1305 M32) () (t M32) (poly1305_key.I.s ()) | {
"file_name": "code/streaming/Hacl.Streaming.Poly1305_32.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 21,
"start_col": 0,
"start_line": 21
} | module Hacl.Streaming.Poly1305_32
module G = FStar.Ghost
module F = Hacl.Streaming.Functor
module I = Hacl.Streaming.Interface
open Hacl.Impl.Poly1305.Fields
open Hacl.Streaming.Poly1305
#set-options "--fuel 0 --ifuel 0 --z3rlimit 100"
/// Type abbreviation - makes KaRaMeL use pretty names in the generated code
let state_t = F.state_s (poly1305 M32) () (t M32) (poly1305_key.I.s ())
noextract
let alloca = F.alloca (poly1305 M32) () (t M32) (poly1305_key.I.s ())
let malloc = F.malloc (poly1305 M32) () (t M32) (poly1305_key.I.s ())
let reset = F.reset (poly1305 M32) (G.hide ()) (t M32) (poly1305_key.I.s ())
[@@ Comment "0 = success, 1 = max length exceeded" ] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Hacl.Streaming.Poly1305.fst.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Impl.Poly1305.Fields.fst.checked",
"Hacl.Impl.Poly1305.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.Poly1305_32.fsti"
} | [
{
"abbrev": false,
"full_module": "Hacl.Streaming.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Fields",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Interface",
"short_module": "I"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Streaming.Functor.digest_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M32)
()
(Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M32)
(Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ()) | Prims.Tot | [
"total"
] | [] | [
"Hacl.Streaming.Functor.digest",
"Prims.unit",
"Hacl.Streaming.Poly1305.poly1305",
"Hacl.Impl.Poly1305.Fields.M32",
"Hacl.Streaming.Poly1305.t",
"Hacl.Streaming.Interface.__proj__Stateful__item__s",
"Hacl.Streaming.Poly1305.poly1305_key"
] | [] | false | false | false | false | false | let digest =
| F.digest (poly1305 M32) () (t M32) (poly1305_key.I.s ()) | false |
|
Steel.ST.HigherArray.fst | Steel.ST.HigherArray.malloc_ptr | val malloc_ptr
(#elt: Type)
(x: elt)
(n: US.t)
: STT(a: ptr elt { base_len (base a) == US.v n /\ offset a == 0 })
emp
(fun a -> pts_to (| a, Ghost.hide (US.v n) |) P.full_perm (Seq.create (US.v n) x)) | val malloc_ptr
(#elt: Type)
(x: elt)
(n: US.t)
: STT(a: ptr elt { base_len (base a) == US.v n /\ offset a == 0 })
emp
(fun a -> pts_to (| a, Ghost.hide (US.v n) |) P.full_perm (Seq.create (US.v n) x)) | let malloc_ptr
x n
=
let a = malloc0 x n in
let (| p, _ |) = a in
rewrite
(pts_to _ _ _)
(pts_to (| p, Ghost.hide (US.v n) |) _ _);
return p | {
"file_name": "lib/steel/Steel.ST.HigherArray.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 10,
"end_line": 297,
"start_col": 0,
"start_line": 289
} | (*
Copyright 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.HigherArray
module P = Steel.PCMFrac
module R = Steel.ST.PCMReference
module M = FStar.Map
module PM = Steel.PCMMap
[@@noextract_to "krml"]
let index_t (len: Ghost.erased nat) : Tot Type0 =
(i: nat { i < len })
[@@noextract_to "krml"]
let carrier (elt: Type u#a) (len: Ghost.erased nat) : Tot Type =
PM.map (index_t len) (P.fractional elt)
[@@noextract_to "krml"]
let pcm (elt: Type u#a) (len: Ghost.erased nat) : Tot (P.pcm (carrier elt len)) =
PM.pointwise (index_t len) (P.pcm_frac #elt)
[@@noextract_to "krml"]
let one (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.one
let composable (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.composable
[@@noextract_to "krml"]
let compose (#elt: Type) (#len: Ghost.erased nat) = (pcm elt len).P.p.P.op
[@@noextract_to "krml"]
let mk_carrier
(#elt: Type)
(len: nat)
(offset: nat)
(s: Seq.seq elt)
(p: P.perm)
: Tot (carrier elt len)
= let f (i: nat) : Tot (P.fractional elt) =
if offset + Seq.length s > len || i < offset || i >= offset + Seq.length s
then None
else Some (Seq.index s (i - offset), p)
in
M.map_literal f
let mk_carrier_inj
(#elt: Type)
(len: nat)
(offset: nat)
(s1 s2: Seq.seq elt)
(p1 p2: P.perm)
: Lemma
(requires (
mk_carrier len offset s1 p1 == mk_carrier len offset s2 p2 /\
offset + Seq.length s1 <= len /\
offset + Seq.length s2 <= len
))
(ensures (
s1 `Seq.equal` s2 /\
(Seq.length s1 > 0 ==> p1 == p2)
))
= assert (forall (i: nat) . i < Seq.length s1 ==>
(M.sel (mk_carrier len offset s1 p1) (offset + i) == Some (Seq.index s1 i, p1)));
assert (forall (i: nat) . i < Seq.length s2 ==>
M.sel (mk_carrier len offset s2 p2) (offset + i) == Some (Seq.index s2 i, p2))
[@@erasable]
let base_t (elt: Type u#a) : Tot Type0 = Ghost.erased (base_len: US.t & ref _ (pcm elt (US.v base_len)))
let base_len (#elt: Type) (b: base_t elt) : GTot nat = US.v (dfst b)
[@@noextract_to "krml"]
noeq
type ptr (elt: Type u#a) : Type0 = {
base_len: Ghost.erased US.t;
// U32.t to prove that A.read, A.write offset computation does not overflow. TODO: replace U32.t with size_t
base: (r: ref _ (pcm elt (US.v base_len)) { core_ref_is_null r ==> US.v base_len == 0 });
offset: (offset: nat { offset <= US.v base_len });
}
let null_ptr a = { base_len = 0sz; base = null #_ #(pcm a 0) ; offset = 0 }
let is_null_ptr p = is_null p.base
let base (#elt: Type) (p: ptr elt) : Tot (base_t elt) = (| Ghost.reveal p.base_len, p.base |)
let offset (#elt: Type) (p: ptr elt) : Ghost nat (requires True) (ensures (fun offset -> offset <= base_len (base p))) = p.offset
let ptr_base_offset_inj (#elt: Type) (p1 p2: ptr elt) : Lemma
(requires (
base p1 == base p2 /\
offset p1 == offset p2
))
(ensures (
p1 == p2
))
= ()
let base_len_null_ptr _ = ()
let length_fits #elt a = ()
let valid_perm
(len: nat)
(offset: nat)
(slice_len: nat)
(p: P.perm) : Tot prop =
let open FStar.Real in
((offset + slice_len <= len /\ slice_len > 0) ==> (p.P.v <=. one))
[@__reduce__]
let pts_to0 (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : Tot vprop =
R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p) `star`
pure (
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
let pts_to (#elt: Type u#1) (a: array elt) ([@@@ smt_fallback ] p: P.perm) ([@@@ smt_fallback ] s: Seq.seq elt) : Tot vprop =
pts_to0 a p s
// this lemma is necessary because Steel.PCMReference is marked unfold
let change_r_pts_to
(#opened: _)
(#carrier: Type u#1)
(#pcm: P.pcm carrier)
(p: ref carrier pcm)
(v: carrier)
(#carrier': Type u#1)
(#pcm': P.pcm carrier')
(p': ref carrier' pcm')
(v': carrier')
: STGhost unit opened
(R.pts_to p v)
(fun _ -> R.pts_to p' v')
(// keep on distinct lines for error messages
carrier == carrier' /\
pcm == pcm' /\
p == p' /\
v == v')
(fun _ -> True)
= rewrite
(R.pts_to p v)
(R.pts_to p' v')
let intro_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (#v: _) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(R.pts_to (ptr_of a).base v)
(fun _ -> pts_to a p s)
(
v == mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p /\
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
(fun _ -> True)
= change_r_pts_to (ptr_of a).base v (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p);
intro_pure _;
rewrite
(pts_to0 a p s)
(pts_to a p s)
let elim_pts_to (#opened: _) (#elt: Type u#1) (a: array elt) (p: P.perm) (s: Seq.seq elt) : STGhost unit opened
(pts_to a p s)
(fun _ -> R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s p))
(True)
(fun _ ->
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s) p /\
Seq.length s == length a
)
= rewrite
(pts_to a p s)
(pts_to0 a p s);
elim_pure _
let pts_to_length
a s
=
elim_pts_to a _ s;
intro_pts_to a _ s
let pts_to_not_null
a s
= elim_pts_to a _ s;
R.pts_to_not_null _ _;
intro_pts_to a _ s
let mk_carrier_joinable
(#elt: Type)
(len: nat)
(offset: nat)
(s1: Seq.seq elt)
(p1: P.perm)
(s2: Seq.seq elt)
(p2: P.perm)
: Lemma
(requires (
offset + Seq.length s1 <= len /\
Seq.length s1 == Seq.length s2 /\
P.joinable (pcm elt len) (mk_carrier len offset s1 p1) (mk_carrier len offset s2 p2)
))
(ensures (
s1 `Seq.equal` s2
))
=
let lem
(i: nat { 0 <= i /\ i < Seq.length s1 })
: Lemma
(Seq.index s1 i == Seq.index s2 i)
[SMTPat (Seq.index s1 i); SMTPat (Seq.index s2 i)]
= assert (
forall z . (
P.compatible (pcm elt len) (mk_carrier len offset s1 p1) z /\
P.compatible (pcm elt len) (mk_carrier len offset s2 p2) z
) ==>
begin match M.sel z (offset + i) with
| None -> False
| Some (v, _) -> v == Seq.index s1 i /\ v == Seq.index s2 i
end
)
in
()
let pure_star_interp' (p:slprop u#a) (q:prop) (m:mem)
: Lemma (interp (p `Steel.Memory.star` Steel.Memory.pure q) m <==>
interp p m /\ q)
= pure_star_interp p q m;
emp_unit p
let pts_to_inj
a p1 s1 p2 s2 m
=
Classical.forall_intro reveal_pure;
pure_star_interp'
(hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1)))
(
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s1) p1 /\
Seq.length s1 == length a
)
m;
pure_star_interp'
(hp_of (R.pts_to (ptr_of a).base (mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2)))
(
valid_perm (US.v (ptr_of a).base_len) (ptr_of a).offset (Seq.length s2) p2 /\
Seq.length s2 == length a
)
m;
pts_to_join
(ptr_of a).base
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1)
(mk_carrier (US.v (ptr_of a).base_len) (ptr_of a).offset s2 p2)
m;
mk_carrier_joinable (US.v (ptr_of a).base_len) (ptr_of a).offset s1 p1 s2 p2
[@@noextract_to "krml"]
let malloc0
(#elt: Type)
(x: elt)
(n: US.t)
: ST (array elt)
emp
(fun a -> pts_to a P.full_perm (Seq.create (US.v n) x))
(True)
(fun a ->
length a == US.v n /\
base_len (base (ptr_of a)) == US.v n
)
=
let c : carrier elt (US.v n) = mk_carrier (US.v n) 0 (Seq.create (US.v n) x) P.full_perm in
let base : ref (carrier elt (US.v n)) (pcm elt (US.v n)) = R.alloc c in
R.pts_to_not_null base _;
let p = {
base_len = n;
base = base;
offset = 0;
}
in
let a = (| p, Ghost.hide (US.v n) |) in
change_r_pts_to
base c
(ptr_of a).base c;
intro_pts_to a P.full_perm (Seq.create (US.v n) x);
return a | {
"checked_file": "/",
"dependencies": [
"Steel.ST.PCMReference.fsti.checked",
"Steel.ST.Loops.fsti.checked",
"Steel.PCMMap.fst.checked",
"Steel.PCMFrac.fst.checked",
"Steel.Memory.fsti.checked",
"prims.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Real.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Map.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": true,
"source_file": "Steel.ST.HigherArray.fst"
} | [
{
"abbrev": true,
"full_module": "Steel.PCMMap",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "FStar.Map",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Steel.ST.PCMReference",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "Steel.PCMFrac",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"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 | x: elt -> n: FStar.SizeT.t
-> Steel.ST.Effect.STT
(a:
Steel.ST.HigherArray.ptr elt
{ Steel.ST.HigherArray.base_len (Steel.ST.HigherArray.base a) == FStar.SizeT.v n /\
Steel.ST.HigherArray.offset a == 0 }) | Steel.ST.Effect.STT | [] | [] | [
"FStar.SizeT.t",
"Steel.ST.HigherArray.ptr",
"FStar.Ghost.erased",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Steel.ST.HigherArray.offset",
"FStar.Ghost.reveal",
"Steel.ST.HigherArray.base_len",
"Steel.ST.HigherArray.base",
"Steel.ST.Util.return",
"Prims.l_and",
"Prims.eq2",
"FStar.SizeT.v",
"Prims.int",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.ST.HigherArray.pts_to",
"Prims.Mkdtuple2",
"Steel.FractionalPermission.full_perm",
"FStar.Seq.Base.create",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.ST.Util.rewrite",
"Steel.ST.HigherArray.array",
"Steel.ST.HigherArray.malloc0"
] | [] | false | true | false | false | false | let malloc_ptr x n =
| let a = malloc0 x n in
let (| p , _ |) = a in
rewrite (pts_to _ _ _) (pts_to (| p, Ghost.hide (US.v n) |) _ _);
return p | false |
Vale.Arch.Types.fst | Vale.Arch.Types.lemma_insert_nat64_nat32s | val lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 ) | val lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 ) | let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 165,
"start_col": 0,
"start_line": 157
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32 -> n0: Vale.Def.Words_s.nat32 -> n1: Vale.Def.Words_s.nat32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Types_s.insert_nat64 q
(Vale.Arch.Types.two_to_nat32 (Vale.Def.Words_s.Mktwo n0 n1))
0 ==
Vale.Def.Words_s.Mkfour n0 n1 (Mkfour?.hi2 q) (Mkfour?.hi3 q) /\
Vale.Def.Types_s.insert_nat64 q
(Vale.Arch.Types.two_to_nat32 (Vale.Def.Words_s.Mktwo n0 n1))
1 ==
Vale.Def.Words_s.Mkfour (Mkfour?.lo0 q) (Mkfour?.lo1 q) n0 n1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Words_s.nat32",
"Prims.unit",
"Vale.Def.Types_s.insert_nat64_reveal",
"Prims.l_True",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"Vale.Def.Words_s.four",
"Vale.Def.Types_s.nat32",
"Vale.Def.Types_s.insert_nat64",
"Vale.Arch.Types.two_to_nat32",
"Vale.Def.Words_s.Mktwo",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_insert_nat64_nat32s (q: quad32) (n0 n1: nat32)
: Lemma
(insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 == Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 == Mkfour q.lo0 q.lo1 n0 n1) =
| let open Vale.Def.Words.Two in
insert_nat64_reveal ();
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.lemma_insert_nat64_properties | val lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
[SMTPat (insert_nat64 q n)] | val lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
[SMTPat (insert_nat64 q n)] | let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 155,
"start_col": 0,
"start_line": 146
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32 -> n: Vale.Def.Words_s.nat64
-> FStar.Pervasives.Lemma
(ensures
(let q' = Vale.Def.Types_s.insert_nat64 q n 0 in
Mkfour?.hi2 q' == Mkfour?.hi2 q /\ Mkfour?.hi3 q' == Mkfour?.hi3 q) /\
(let q' = Vale.Def.Types_s.insert_nat64 q n 1 in
Mkfour?.lo0 q' == Mkfour?.lo0 q /\ Mkfour?.lo1 q' == Mkfour?.lo1 q))
[SMTPat (Vale.Def.Types_s.insert_nat64 q n)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Words_s.nat64",
"Prims.unit",
"Vale.Def.Types_s.insert_nat64_reveal",
"Prims.l_True",
"Prims.squash",
"Prims.l_and",
"Prims.eq2",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.insert_nat64",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let lemma_insert_nat64_properties (q: quad32) (n: nat64)
: Lemma
((let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\ q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\ q'.lo1 == q.lo1)) =
| insert_nat64_reveal ();
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.lemma_insrq_extrq_relations | val lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3)) | val lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3)) | let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 297,
"start_col": 0,
"start_line": 274
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 3,
"initial_ifuel": 3,
"max_fuel": 3,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.Def.Types_s.quad32 -> y: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
(let z = Vale.Def.Types_s.insert_nat64 x (Vale.Arch.Types.lo64 y) 0 in
z == Vale.Def.Words_s.Mkfour (Mkfour?.lo0 y) (Mkfour?.lo1 y) (Mkfour?.hi2 x) (Mkfour?.hi3 x) /\
(let z = Vale.Def.Types_s.insert_nat64 x (Vale.Arch.Types.hi64 y) 1 in
z ==
Vale.Def.Words_s.Mkfour (Mkfour?.lo0 x) (Mkfour?.lo1 x) (Mkfour?.hi2 y) (Mkfour?.hi3 y)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.nat32",
"Prims.unit",
"Vale.Def.Words.Two.nat_to_two_to_nat",
"Vale.Def.Words_s.two",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words.Two_s.two_select",
"Vale.Def.Words.Four_s.four_to_two_two",
"Prims._assert",
"Prims.eq2",
"Vale.Def.Types_s.insert_nat64_def",
"Vale.Arch.Types.lo64_def",
"Vale.Arch.Types.hi64_reveal",
"Vale.Arch.Types.lo64_reveal",
"Vale.Def.Types_s.insert_nat64_reveal",
"Vale.Def.Types_s.insert_nat64",
"Vale.Arch.Types.lo64",
"Prims.l_True",
"Prims.squash",
"Prims.l_and",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Arch.Types.hi64",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_insrq_extrq_relations (x y: quad32)
: Lemma
(let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3)) =
| let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.le_bytes_to_seq_quad32_empty | val le_bytes_to_seq_quad32_empty: unit ->
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0) | val le_bytes_to_seq_quad32_empty: unit ->
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0) | let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 314,
"start_col": 0,
"start_line": 310
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal () | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 3,
"initial_ifuel": 3,
"max_fuel": 3,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
forall (s: FStar.Seq.Base.seq Vale.Def.Types_s.nat8).
{:pattern FStar.Seq.Base.length (Vale.Def.Types_s.le_bytes_to_seq_quad32 s)}
FStar.Seq.Base.length s == 0 ==>
FStar.Seq.Base.length (Vale.Def.Types_s.le_bytes_to_seq_quad32 s) == 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat8",
"Vale.Def.Types_s.quad32",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.l_True",
"Vale.Def.Types_s.le_bytes_to_seq_quad32",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let le_bytes_to_seq_quad32_empty ()
: Lemma
(forall s. {:pattern (length (le_bytes_to_seq_quad32 s))}
length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0) =
| reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.push_pop_xmm | val push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x') | val push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x') | let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 271,
"start_col": 0,
"start_line": 263
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Vale.Def.Types_s.quad32 -> y: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
(let x' =
Vale.Def.Types_s.insert_nat64 (Vale.Def.Types_s.insert_nat64 y (Vale.Arch.Types.hi64 x) 1)
(Vale.Arch.Types.lo64 x)
0
in
x == x')) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.unit",
"Vale.Arch.Types.hi64_reveal",
"Vale.Arch.Types.lo64_reveal",
"Vale.Def.Types_s.insert_nat64_reveal",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.Def.Types_s.insert_nat64",
"Vale.Arch.Types.hi64",
"Vale.Arch.Types.lo64",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let push_pop_xmm (x y: quad32)
: Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x') =
| insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.lemma_equality_check_helper | val lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
) | val lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
) | let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 260,
"start_col": 0,
"start_line": 246
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
(Mkfour?.lo0 q == 0 /\ Mkfour?.lo1 q == 0 ==> Vale.Arch.Types.lo64 q == 0) /\
(Prims.op_Negation (Mkfour?.lo0 q = 0) \/ Prims.op_Negation (Mkfour?.lo1 q = 0) ==>
Prims.op_Negation (Vale.Arch.Types.lo64 q = 0)) /\
(Mkfour?.hi2 q == 0 /\ Mkfour?.hi3 q == 0 ==> Vale.Arch.Types.hi64 q == 0) /\
(~(Mkfour?.hi2 q = 0) \/ ~(Mkfour?.hi3 q = 0) ==> ~(Vale.Arch.Types.hi64 q = 0)) /\
(Mkfour?.lo0 q == 0xFFFFFFFF /\ Mkfour?.lo1 q == 0xFFFFFFFF <==>
Vale.Arch.Types.lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(Mkfour?.hi2 q == 0xFFFFFFFF /\ Mkfour?.hi3 q == 0xFFFFFFFF <==>
Vale.Arch.Types.hi64 q == 0xFFFFFFFFFFFFFFFF)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.unit",
"Prims._assert",
"Prims.l_Forall",
"Vale.Def.Words_s.two",
"Vale.Def.Words_s.nat32",
"Prims.eq2",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words.Two_s.two_to_nat",
"Vale.Def.Words.Two_s.two_to_nat_unfold",
"Vale.Arch.Types.hi64_reveal",
"Vale.Arch.Types.lo64_reveal",
"Prims.l_True",
"Prims.squash",
"Prims.l_and",
"Prims.l_imp",
"Prims.int",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Arch.Types.lo64",
"Prims.l_or",
"Prims.b2t",
"Prims.op_Negation",
"Prims.op_Equality",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Arch.Types.hi64",
"Prims.l_not",
"Prims.l_iff",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_equality_check_helper (q: quad32)
: Lemma
((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)) =
| lo64_reveal ();
hi64_reveal ();
assert (forall (x: two nat32). {:pattern (two_to_nat 32 x)}
two_to_nat 32 x == two_to_nat_unfold 32 x);
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes | val le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s) | val le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s) | let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 380,
"start_col": 0,
"start_line": 361
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
} | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Types_s.le_seq_quad32_to_bytes s) == s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Prims.unit",
"Vale.Def.Words.Seq.seq_to_seq_four_to_seq_LE",
"Vale.Def.Types_s.nat32",
"Vale.Lib.Seqs.seq_map_inverses",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Seq_s.seq_four_to_seq_LE",
"Vale.Lib.Seqs_s.seq_map",
"Vale.Def.Types_s.le_seq_quad32_to_bytes_reveal",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.l_True",
"Vale.Def.Types_s.le_bytes_to_seq_quad32",
"Prims.squash",
"Vale.Def.Types_s.le_seq_quad32_to_bytes",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let le_bytes_to_seq_quad32_to_bytes (s: seq quad32)
: Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s) =
| reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s);
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.le_seq_quad32_to_bytes_to_seq_quad32 | val le_seq_quad32_to_bytes_to_seq_quad32 (s:seq nat8{length s % 16 = 0}) :
Lemma (le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s) == s) | val le_seq_quad32_to_bytes_to_seq_quad32 (s:seq nat8{length s % 16 = 0}) :
Lemma (le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s) == s) | let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
} | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 400,
"start_col": 0,
"start_line": 391
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length s % 16 = 0}
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Types_s.le_seq_quad32_to_bytes (Vale.Def.Types_s.le_bytes_to_seq_quad32 s) == s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"FStar.Calc.calc_finish",
"Vale.Def.Types_s.nat8",
"Prims.eq2",
"Vale.Def.Types_s.le_seq_quad32_to_bytes",
"Vale.Def.Types_s.le_bytes_to_seq_quad32",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_LE",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words.Seq_s.seq_to_seq_four_LE",
"Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"Vale.Def.Types_s.le_seq_quad32_to_bytes_reveal",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.quad32",
"Prims.l_True"
] | [] | false | false | true | false | false | let le_seq_quad32_to_bytes_to_seq_quad32 s =
| reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc ( == ) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
( == ) { () }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
( == ) { () }
s;
} | false |
CustomSyntax.fst | CustomSyntax.sum_spec | val sum_spec (n: nat) : GTot nat | val sum_spec (n: nat) : GTot nat | let rec sum_spec (n:nat) : GTot nat =
if n = 0 then 0 else n + sum_spec (n - 1) | {
"file_name": "share/steel/examples/pulse/CustomSyntax.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 43,
"end_line": 288,
"start_col": 0,
"start_line": 287
} | (*
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 CustomSyntax
open Pulse.Lib.Pervasives
module U32 = FStar.UInt32
#push-options "--using_facts_from '* -FStar.Tactics -FStar.Reflection'"
#push-options "--ide_id_info_off"
assume val p : vprop
assume val g : unit -> stt unit emp (fun _ -> p)
let folded_pts_to (r:ref U32.t) (n:erased U32.t) : vprop = pts_to r n
```pulse
fn unfold_test (r:ref U32.t)
requires folded_pts_to r 'n
ensures folded_pts_to r 'n
{
unfold folded_pts_to;
fold folded_pts_to
}
```
```pulse
fn test_write_10 (x:ref U32.t)
requires pts_to x 'n
ensures pts_to x 0ul
{
x := 1ul;
x := 0ul;
}
```
```pulse
fn test_read (r:ref U32.t)
requires pts_to r #pm 'n
returns x : U32.t
ensures pts_to r #pm x
{
!r
}
```
```pulse
fn swap (r1 r2:ref U32.t)
requires
pts_to r1 'n1 **
pts_to r2 'n2
ensures
pts_to r1 'n2 **
pts_to r2 'n1
{
let x = !r1;
let y = !r2;
r1 := y;
r2 := x
}
```
```pulse
fn call_swap2 (r1 r2:ref U32.t)
requires
pts_to r1 'n1 **
pts_to r2 'n2
ensures
pts_to r1 'n1 **
pts_to r2 'n2
{
swap r1 r2;
swap r1 r2
}
```
```pulse
fn swap_with_elim_pure (#n1 #n2:erased U32.t)
(r1 r2:ref U32.t)
requires
pts_to r1 n1 **
pts_to r2 n2
ensures
pts_to r1 n2 **
pts_to r2 n1
{
let x = !r1;
let y = !r2;
r1 := y;
r2 := x
}
```
```pulse
fn intro_pure_example (r:ref U32.t)
requires
(pts_to r 'n1 **
pure (reveal 'n1 == reveal 'n2))
ensures
(pts_to r 'n2 **
pure (reveal 'n2 == reveal 'n1))
{
()
}
```
```pulse
fn if_example (r:ref U32.t)
(n:(n:erased U32.t{U32.v (reveal n) == 1}))
(b:bool)
requires
pts_to r n
ensures
pts_to r (U32.add (reveal n) 2ul)
{
let x = read_atomic r;
if b
{
r := U32.add x 2ul
}
else
{
write_atomic r 3ul
}
}
```
```pulse
ghost
fn elim_intro_exists2 (r:ref U32.t)
requires
exists* n. pts_to r n
ensures
exists* n. pts_to r n
{
introduce exists* n. pts_to r n with _
}
```
assume
val pred (b:bool) : vprop
assume
val read_pred () (#b:erased bool)
: stt bool (pred b) (fun r -> pred r)
```pulse
fn while_test_alt (r:ref U32.t)
requires
exists* b n.
(pts_to r n **
pred b)
ensures
exists* n. (pts_to r n **
pred false)
{
while (read_pred ())
invariant b . exists* n. (pts_to r n ** pred b)
{
()
}
}
```
```pulse
fn infer_read_ex (r:ref U32.t)
requires
exists* n. pts_to r n
ensures exists* n. pts_to r n
{
let x = !r;
()
}
```
```pulse
fn while_count2 (r:ref U32.t)
requires exists* (n:U32.t). (pts_to r n)
ensures (pts_to r 10ul)
{
open FStar.UInt32;
while (let x = !r; (x <> 10ul))
invariant b.
exists* n. (pts_to r n **
pure (b == (n <> 10ul)))
{
let x = !r;
if (x <^ 10ul)
{
r := x +^ 1ul
}
else
{
r := x -^ 1ul
}
}
}
```
```pulse
fn test_par (r1 r2:ref U32.t)
requires
pts_to r1 'n1 **
pts_to r2 'n2
ensures
pts_to r1 1ul **
pts_to r2 1ul
{
parallel
requires (pts_to r1 'n1)
and (pts_to r2 'n2)
ensures (pts_to r1 1ul)
and (pts_to r2 1ul)
{
r1 := 1ul
}
{
r2 := 1ul
};
()
}
```
// A test for rewrite
let mpts_to (r:ref U32.t) (n:erased U32.t) : vprop = pts_to r n
```pulse
fn rewrite_test (r:ref U32.t)
requires (mpts_to r 'n)
ensures (mpts_to r 1ul)
{
rewrite (mpts_to r 'n)
as (pts_to r 'n);
r := 1ul;
rewrite (pts_to r 1ul)
as (mpts_to r 1ul)
}
```
```pulse
fn test_local (r:ref U32.t)
requires (pts_to r 'n)
ensures (pts_to r 0ul)
{
let mut x = 0ul;
let y = Pulse.Lib.Reference.op_Bang x;
r := y
}
```
```pulse
fn count_local (r:ref int) (n:int)
requires (pts_to r (hide 0))
ensures (pts_to r n)
{
let mut i = 0;
while
(let m = !i; (m <> n))
invariant b. exists* m.
(pts_to i m **
pure (b == (m <> n)))
{
let m = !i;
i := m + 1
};
let x = !i;
r := x
}
``` | {
"checked_file": "/",
"dependencies": [
"Pulse.Lib.Pervasives.fst.checked",
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "CustomSyntax.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "Pulse.Lib.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | n: Prims.nat -> Prims.GTot Prims.nat | Prims.GTot | [
"sometrivial"
] | [] | [
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Prims.op_Addition",
"CustomSyntax.sum_spec",
"Prims.op_Subtraction"
] | [
"recursion"
] | false | false | false | false | false | let rec sum_spec (n: nat) : GTot nat =
| if n = 0 then 0 else n + sum_spec (n - 1) | false |
Vale.Arch.Types.fst | Vale.Arch.Types.be_seq_quad32_to_bytes_of_singleton | val be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q))) | val be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q))) | let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 453,
"start_col": 0,
"start_line": 448
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Arch.Types.be_quad32_to_bytes q ==
Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE (FStar.Seq.Base.create
1
q))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.unit",
"Vale.Def.Words.Seq.four_to_seq_BE_is_seq_four_to_seq_BE",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Words.Seq_s.seq16",
"Vale.Def.Words_s.nat8",
"Vale.Arch.Types.be_quad32_to_bytes",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Words_s.nat32",
"FStar.Seq.Base.create",
"Vale.Def.Words_s.four",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let be_seq_quad32_to_bytes_of_singleton (q: quad32)
: Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q))) =
| reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.be_bytes_to_seq_quad32_empty | val be_bytes_to_seq_quad32_empty: unit ->
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0) | val be_bytes_to_seq_quad32_empty: unit ->
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0) | let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 320,
"start_col": 0,
"start_line": 316
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 3,
"initial_ifuel": 3,
"max_fuel": 3,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
forall (s: FStar.Seq.Base.seq Vale.Def.Types_s.nat8).
{:pattern FStar.Seq.Base.length (Vale.Def.Types_s.be_bytes_to_seq_quad32 s)}
FStar.Seq.Base.length s == 0 ==>
FStar.Seq.Base.length (Vale.Def.Types_s.be_bytes_to_seq_quad32 s) == 0) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Pervasives.reveal_opaque",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat8",
"Vale.Def.Types_s.quad32",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.l_True",
"Vale.Def.Types_s.be_bytes_to_seq_quad32",
"Prims.squash",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let be_bytes_to_seq_quad32_empty ()
: Lemma
(forall s. {:pattern (length (be_bytes_to_seq_quad32 s))}
length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0) =
| reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.le_seq_quad32_to_bytes_injective | val le_seq_quad32_to_bytes_injective (b b':Seq.seq quad32) : Lemma
(requires Seq.equal (le_seq_quad32_to_bytes b) (le_seq_quad32_to_bytes b'))
(ensures b == b') | val le_seq_quad32_to_bytes_injective (b b':Seq.seq quad32) : Lemma
(requires Seq.equal (le_seq_quad32_to_bytes b) (le_seq_quad32_to_bytes b'))
(ensures b == b') | let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b') | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 515,
"start_col": 0,
"start_line": 509
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> b': FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(requires
FStar.Seq.Base.equal (Vale.Def.Types_s.le_seq_quad32_to_bytes b)
(Vale.Def.Types_s.le_seq_quad32_to_bytes b')) (ensures b == b') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Prims._assert",
"FStar.Seq.Base.equal",
"Prims.unit",
"Vale.Def.Words.Seq.seq_four_to_seq_LE_injective_specific",
"Vale.Def.Types_s.nat32",
"Vale.Lib.Seqs.seq_map_injective",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words.Seq_s.seq_four_to_seq_LE",
"Vale.Def.Words.Seq.nat_to_four_8_injective",
"Vale.Def.Words.Seq.seq_four_to_seq_LE_injective",
"Vale.Def.Words_s.nat8",
"Vale.Def.Types_s.le_seq_quad32_to_bytes_reveal"
] | [] | true | false | true | false | false | let le_seq_quad32_to_bytes_injective (b b': seq quad32) =
| le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective ();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b') | false |
Vale.Arch.Types.fst | Vale.Arch.Types.le_seq_quad32_to_bytes_of_singleton | val le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)) | val le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)) | let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 446,
"start_col": 0,
"start_line": 440
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
} | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Types_s.le_quad32_to_bytes q ==
Vale.Def.Types_s.le_seq_quad32_to_bytes (FStar.Seq.Base.create 1 q)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.unit",
"Vale.Def.Words.Seq.four_to_seq_LE_is_seq_four_to_seq_LE",
"Vale.Def.Types_s.nat32",
"FStar.Pervasives.reveal_opaque",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat8",
"Prims.l_True",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Vale.Def.Types_s.le_quad32_to_bytes",
"Vale.Def.Types_s.le_seq_quad32_to_bytes_reveal",
"Prims.squash",
"Vale.Def.Types_s.le_seq_quad32_to_bytes",
"FStar.Seq.Base.create",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let le_seq_quad32_to_bytes_of_singleton (q: quad32)
: Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)) =
| le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.be_quad32_to_bytes_injective_specific | val be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') | val be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') | let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 507,
"start_col": 0,
"start_line": 504
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.Def.Types_s.quad32 -> b': Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Arch.Types.be_quad32_to_bytes b == Vale.Arch.Types.be_quad32_to_bytes b' ==> b == b') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Arch.Types.be_quad32_to_bytes_injective",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Prims.eq2",
"Vale.Def.Words.Seq_s.seq16",
"Vale.Def.Words_s.nat8",
"Vale.Arch.Types.be_quad32_to_bytes",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let be_quad32_to_bytes_injective_specific (b b': quad32)
: Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
| be_quad32_to_bytes_injective () | false |
Vale.Arch.Types.fst | Vale.Arch.Types.le_quad32_to_bytes_injective_specific | val le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') | val le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') | let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 502,
"start_col": 0,
"start_line": 499
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.Def.Types_s.quad32 -> b': Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Types_s.le_quad32_to_bytes b == Vale.Def.Types_s.le_quad32_to_bytes b' ==> b == b') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Arch.Types.le_quad32_to_bytes_injective",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat8",
"Vale.Def.Types_s.le_quad32_to_bytes",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let le_quad32_to_bytes_injective_specific (b b': quad32)
: Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
| le_quad32_to_bytes_injective () | false |
Vale.Arch.Types.fst | Vale.Arch.Types.be_bytes_to_seq_quad32_to_bytes | val be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s) | val be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s) | let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 389,
"start_col": 0,
"start_line": 382
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Types_s.be_bytes_to_seq_quad32 (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
s)) ==
s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Prims.unit",
"Vale.Def.Words.Seq.seq_to_seq_four_to_seq_BE",
"Vale.Def.Types_s.nat32",
"Vale.Lib.Seqs.seq_map_inverses",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Lib.Seqs_s.seq_map",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.l_True",
"Vale.Def.Types_s.be_bytes_to_seq_quad32",
"Prims.squash",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let be_bytes_to_seq_quad32_to_bytes (s: seq quad32)
: Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s) =
| reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s);
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.le_bytes_to_nat64_to_bytes | val le_bytes_to_nat64_to_bytes (s:nat64) :
Lemma (le_bytes_to_nat64 (le_nat64_to_bytes s) == s) | val le_bytes_to_nat64_to_bytes (s:nat64) :
Lemma (le_bytes_to_nat64 (le_nat64_to_bytes s) == s) | let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal () | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 303,
"start_col": 0,
"start_line": 301
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 3,
"initial_ifuel": 3,
"max_fuel": 3,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Vale.Def.Words_s.nat64
-> FStar.Pervasives.Lemma
(ensures Vale.Def.Types_s.le_bytes_to_nat64 (Vale.Def.Types_s.le_nat64_to_bytes s) == s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words_s.nat64",
"Vale.Def.Types_s.le_bytes_to_nat64_reveal",
"Prims.unit",
"Vale.Def.Types_s.le_nat64_to_bytes_reveal"
] | [] | true | false | true | false | false | let le_bytes_to_nat64_to_bytes s =
| le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal () | false |
Vale.Arch.Types.fst | Vale.Arch.Types.le_quad32_to_bytes_injective | val le_quad32_to_bytes_injective: unit ->
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') | val le_quad32_to_bytes_injective: unit ->
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') | let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 475,
"start_col": 0,
"start_line": 455
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
forall (b: Vale.Def.Types_s.quad32) (b': Vale.Def.Types_s.quad32).
Vale.Def.Types_s.le_quad32_to_bytes b == Vale.Def.Types_s.le_quad32_to_bytes b' ==> b == b') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.forall_intro_2",
"Vale.Def.Types_s.quad32",
"Prims.l_imp",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.nat8",
"Vale.Def.Types_s.le_quad32_to_bytes",
"Prims.l_True",
"Prims.squash",
"Vale.Def.Words_s.nat8",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.op_Equality",
"Vale.Def.Words.Seq.four_to_seq_LE_injective",
"Vale.Def.Words_s.nat32",
"Prims._assert",
"Vale.Def.Words.Seq_s.seq4",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words.Seq_s.four_to_seq_LE",
"Vale.Lib.Seqs.seq_map_injective",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words.Seq.nat_to_four_8_injective",
"Vale.Def.Words.Seq.seq_four_to_seq_LE_injective_specific",
"Vale.Def.Words.Seq_s.seq_four_to_seq_LE",
"Vale.Lib.Seqs_s.seq_map",
"Prims.bool",
"FStar.Pervasives.reveal_opaque",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.l_Forall"
] | [] | false | false | true | false | false | let le_quad32_to_bytes_injective ()
: Lemma (forall b b'. le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
| reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b': quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b'
then
(let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective ();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
())
in
FStar.Classical.forall_intro_2 helper | false |
Vale.Arch.Types.fst | Vale.Arch.Types.le_nat64_to_bytes_to_nat64 | val le_nat64_to_bytes_to_nat64 (s:seq nat8 { length s == 8 }) :
Lemma (le_nat64_to_bytes (le_bytes_to_nat64 s) == s) | val le_nat64_to_bytes_to_nat64 (s:seq nat8 { length s == 8 }) :
Lemma (le_nat64_to_bytes (le_bytes_to_nat64 s) == s) | let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal () | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 307,
"start_col": 0,
"start_line": 305
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal () | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 3,
"initial_ifuel": 3,
"max_fuel": 3,
"max_ifuel": 3,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length s == 8}
-> FStar.Pervasives.Lemma
(ensures Vale.Def.Types_s.le_nat64_to_bytes (Vale.Def.Types_s.le_bytes_to_nat64 s) == s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Vale.Def.Types_s.le_bytes_to_nat64_reveal",
"Prims.unit",
"Vale.Def.Types_s.le_nat64_to_bytes_reveal"
] | [] | true | false | true | false | false | let le_nat64_to_bytes_to_nat64 n =
| le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal () | false |
Vale.Arch.Types.fst | Vale.Arch.Types.be_quad32_to_bytes_injective | val be_quad32_to_bytes_injective: unit ->
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') | val be_quad32_to_bytes_injective: unit ->
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') | let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 497,
"start_col": 0,
"start_line": 477
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit
-> FStar.Pervasives.Lemma
(ensures
forall (b: Vale.Def.Types_s.quad32) (b': Vale.Def.Types_s.quad32).
Vale.Arch.Types.be_quad32_to_bytes b == Vale.Arch.Types.be_quad32_to_bytes b' ==> b == b') | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.unit",
"FStar.Classical.forall_intro_2",
"Vale.Def.Types_s.quad32",
"Prims.l_imp",
"Prims.eq2",
"Vale.Def.Words.Seq_s.seq16",
"Vale.Def.Words_s.nat8",
"Vale.Arch.Types.be_quad32_to_bytes",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims.op_Equality",
"Vale.Def.Words.Seq.four_to_seq_BE_injective",
"Vale.Def.Words_s.nat32",
"Prims._assert",
"Vale.Def.Words.Seq_s.seq4",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words.Seq_s.four_to_seq_BE",
"Vale.Lib.Seqs.seq_map_injective",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words.Seq.nat_to_four_8_injective",
"FStar.Seq.Base.seq",
"Vale.Def.Words.Seq.seq_four_to_seq_BE_injective_specific",
"Prims.l_or",
"Prims.int",
"FStar.Seq.Base.length",
"FStar.Mul.op_Star",
"Prims.nat",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Lib.Seqs_s.seq_map",
"Prims.bool",
"FStar.Pervasives.reveal_opaque",
"Prims.l_Forall"
] | [] | false | false | true | false | false | let be_quad32_to_bytes_injective ()
: Lemma (forall b b'. be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
| reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b': quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b'
then
(let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective ();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
())
in
FStar.Classical.forall_intro_2 helper | false |
Vale.Arch.Types.fst | Vale.Arch.Types.seq_to_four_LE_is_seq_to_seq_four_LE | val seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s) | val seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s) | let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 522,
"start_col": 0,
"start_line": 517
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b') | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Vale.Def.Words.Seq_s.seq4 a
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.create 1 (Vale.Def.Words.Seq_s.seq_to_four_LE s) ==
Vale.Def.Words.Seq_s.seq_to_seq_four_LE s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words.Seq_s.seq4",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Words_s.four",
"FStar.Seq.Base.create",
"Vale.Def.Words.Seq_s.seq_to_four_LE",
"Vale.Def.Words.Seq_s.seq_to_seq_four_LE",
"FStar.Pervasives.reveal_opaque",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.op_Division",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let seq_to_four_LE_is_seq_to_seq_four_LE (#a: Type) (s: seq4 a)
: Lemma (create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s) =
| reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.lemma_reverse_reverse_bytes_nat32_quad32 | val lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))] | val lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))] | let lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
=
let s' = reverse_bytes_nat32_quad32 s in
let s''= reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0)); // OBSERVE
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1)); // OBSERVE
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2)); // OBSERVE
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3)); // OBSERVE
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 590,
"start_col": 0,
"start_line": 580
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
()
let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Arch.Types.reverse_bytes_nat32_quad32 (Vale.Arch.Types.reverse_bytes_nat32_quad32 s) ==
s)
[
SMTPat (Vale.Arch.Types.reverse_bytes_nat32_quad32 (Vale.Arch.Types.reverse_bytes_nat32_quad32
s))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Types_s.reverse_bytes_nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__lo1",
"Vale.Def.Words_s.__proj__Mkfour__item__lo0",
"Vale.Arch.Types.reverse_bytes_nat32_quad32",
"Prims.l_True",
"Prims.squash",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let lemma_reverse_reverse_bytes_nat32_quad32 (s: quad32)
: Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))] =
| let s' = reverse_bytes_nat32_quad32 s in
let s'' = reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0));
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1));
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2));
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3));
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.le_bytes_to_quad32_to_bytes | val le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q) | val le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q) | let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 568,
"start_col": 0,
"start_line": 555
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures Vale.Def.Types_s.le_bytes_to_quad32 (Vale.Def.Types_s.le_quad32_to_bytes q) == q) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.index",
"FStar.Seq.Base.create",
"Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes",
"Vale.Arch.Types.le_bytes_to_seq_quad_of_singleton",
"Vale.Def.Types_s.le_bytes_to_quad32",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Vale.Def.Types_s.le_quad32_to_bytes",
"Vale.Arch.Types.le_seq_quad32_to_bytes_of_singleton",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let le_bytes_to_quad32_to_bytes (q: quad32) : Lemma (le_bytes_to_quad32 (le_quad32_to_bytes q) == q) =
| le_seq_quad32_to_bytes_of_singleton q;
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b;
le_bytes_to_seq_quad32_to_bytes (create 1 q);
assert (q == index (create 1 q) 0);
assert (q == q');
() | false |
SteelFramingTestSuite.fst | SteelFramingTestSuite.test7 | val test7: unit -> SteelT ref emp ptr | val test7: unit -> SteelT ref emp ptr | let test7 (_:unit) : SteelT ref emp ptr
= let r = alloc 0 in
let x = read r in
write r 0;
r | {
"file_name": "share/steel/tests/SteelFramingTestSuite.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 103,
"start_col": 0,
"start_line": 99
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module SteelFramingTestSuite
open Steel.Memory
open Steel.Effect
/// A collection of small unit tests for the framing tactic
assume val p : vprop
assume val f (x:int) : SteelT unit p (fun _ -> p)
let test () : SteelT unit (p `star` p `star` p) (fun _ -> p `star` p `star` p)
= f 0; ()
assume val ref : Type0
assume val ptr (_:ref) : vprop
assume val alloc (x:int) : SteelT ref emp (fun y -> ptr y)
assume val free (r:ref) : SteelT unit (ptr r) (fun _ -> emp)
assume val read (r:ref) : SteelT int (ptr r) (fun _ -> ptr r)
assume val write (r:ref) (v: int) : SteelT unit (ptr r) (fun _ -> ptr r)
let unused x = x // work around another gensym heisenbug
let test0 (b1 b2 b3: ref) : SteelT int
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b1 `star` ptr b2 `star` ptr b3)
=
let x = read b1 in
x
let test1 (b1 b2 b3: ref) : SteelT int
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b1 `star` ptr b2 `star` ptr b3)
=
let x = (let y = read b1 in y) in
x
let test2 (b1 b2 b3: ref) : SteelT int
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b3 `star` ptr b2 `star` ptr b1)
=
let x = read b1 in
x
let test3 (b1 b2 b3: ref) : SteelT int
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
=
let x = read b3 in
x
let test4 (b1 b2 b3: ref) : SteelT unit
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
=
let x = read b3 in
write b2 x
let test5 (b1 b2 b3: ref) : SteelT unit
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
=
let x = read b3 in
write b2 (x + 1)
let test6 (b1 b2 b3: ref) : SteelT unit
(ptr b1 `star` ptr b2 `star` ptr b3)
(fun _ -> ptr b2 `star` ptr b1 `star` ptr b3)
=
let x = read b3 in
let b4 = alloc x in
write b2 (x + 1);
free b4
// With the formalism relying on can_be_split_post, this example fails if we normalize return_pre eqs goals before unification
// When solving this equality, we have the goal
// (*?u19*) _ _ == return_pre ((fun x -> (fun x -> (*?u758*) _ x x) x) r)
// with x and r in the context of ?u19
// Not normalizing allows us to solve it as a function applied to x and r
// Normalizing would lead to solve it to an slprop with x and r in the context,
// but which would later fail when trying to prove the equivalence with (fun r -> ptr r) | {
"checked_file": "/",
"dependencies": [
"Steel.Memory.fsti.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "SteelFramingTestSuite.fst"
} | [
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> Steel.Effect.SteelT SteelFramingTestSuite.ref | Steel.Effect.SteelT | [] | [] | [
"Prims.unit",
"SteelFramingTestSuite.ref",
"SteelFramingTestSuite.write",
"Prims.int",
"SteelFramingTestSuite.read",
"SteelFramingTestSuite.alloc",
"Steel.Effect.Common.emp",
"SteelFramingTestSuite.ptr"
] | [] | false | true | false | false | false | let test7 (_: unit) : SteelT ref emp ptr =
| let r = alloc 0 in
let x = read r in
write r 0;
r | false |
Vale.Arch.Types.fst | Vale.Arch.Types.le_bytes_to_seq_quad_of_singleton | val le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b) | val le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b) | let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 544,
"start_col": 0,
"start_line": 531
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
q: Vale.Def.Types_s.quad32 ->
b: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length b == 16}
-> FStar.Pervasives.Lemma (requires q == Vale.Def.Types_s.le_bytes_to_quad32 b)
(ensures FStar.Seq.Base.create 1 q == Vale.Def.Types_s.le_bytes_to_seq_quad32 b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.unit",
"Vale.Arch.Types.seq_to_four_LE_is_seq_to_seq_four_LE",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Lib.Seqs_s.seq_map",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Seq_s.seq_to_seq_four_LE",
"Vale.Def.Types_s.le_bytes_to_quad32_reveal",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Prims.op_Modulus",
"Prims.l_True",
"Vale.Def.Types_s.le_bytes_to_seq_quad32",
"Vale.Def.Types_s.le_bytes_to_quad32",
"Prims.squash",
"FStar.Seq.Base.create",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let le_bytes_to_seq_quad_of_singleton (q: quad32) (b: seq nat8 {length b == 16})
: Lemma (requires q == le_bytes_to_quad32 b) (ensures create 1 q == le_bytes_to_seq_quad32 b) =
| reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.be_bytes_to_quad32_to_bytes | val be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
[SMTPat (be_bytes_to_quad32 (be_quad32_to_bytes q))] | val be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
[SMTPat (be_bytes_to_quad32 (be_quad32_to_bytes q))] | let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 578,
"start_col": 0,
"start_line": 570
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | q: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures Vale.Def.Types_s.be_bytes_to_quad32 (Vale.Arch.Types.be_quad32_to_bytes q) == q)
[SMTPat (Vale.Def.Types_s.be_bytes_to_quad32 (Vale.Arch.Types.be_quad32_to_bytes q))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Prims.unit",
"Vale.Def.Words.Seq.seq_to_four_to_seq_BE",
"Vale.Def.Types_s.nat32",
"Vale.Lib.Seqs.seq_map_inverses",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Seq_s.four_to_seq_BE",
"Vale.Def.Words.Seq.seq_to_seq_four_to_seq_BE",
"Vale.Lib.Seqs_s.seq_map",
"Vale.Def.Types_s.be_bytes_to_quad32",
"Vale.Arch.Types.be_quad32_to_bytes",
"Vale.Def.Types_s.be_bytes_to_quad32_reveal",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let be_bytes_to_quad32_to_bytes (q: quad32) : Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q) =
| be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.lemma_reverse_reverse_bytes_quad32_seq | val lemma_reverse_reverse_bytes_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))] | val lemma_reverse_reverse_bytes_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))] | let lemma_reverse_reverse_bytes_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))]
=
seq_map_inverses reverse_bytes_quad32 reverse_bytes_quad32 s | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 602,
"start_col": 0,
"start_line": 598
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
()
let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
()
let lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
=
let s' = reverse_bytes_nat32_quad32 s in
let s''= reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0)); // OBSERVE
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1)); // OBSERVE
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2)); // OBSERVE
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3)); // OBSERVE
()
let lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))]
=
seq_map_inverses reverse_bytes_nat32_quad32 reverse_bytes_nat32_quad32 s | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Arch.Types.reverse_bytes_quad32_seq (Vale.Arch.Types.reverse_bytes_quad32_seq s) == s)
[
SMTPat (Vale.Arch.Types.reverse_bytes_quad32_seq (Vale.Arch.Types.reverse_bytes_quad32_seq s
))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Vale.Lib.Seqs.seq_map_inverses",
"Vale.Def.Types_s.reverse_bytes_quad32",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.Arch.Types.reverse_bytes_quad32_seq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let lemma_reverse_reverse_bytes_quad32_seq (s: seq quad32)
: Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))] =
| seq_map_inverses reverse_bytes_quad32 reverse_bytes_quad32 s | false |
Vale.Arch.Types.fst | Vale.Arch.Types.be_bytes_to_seq_quad_of_singleton | val be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b) | val be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b) | let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 553,
"start_col": 0,
"start_line": 546
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
q: Vale.Def.Types_s.quad32 ->
b: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length b == 16}
-> FStar.Pervasives.Lemma (requires q == Vale.Def.Types_s.be_bytes_to_quad32 b)
(ensures FStar.Seq.Base.create 1 q == Vale.Def.Types_s.be_bytes_to_seq_quad32 b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"Prims.unit",
"Vale.Arch.Types.seq_to_four_BE_is_seq_to_seq_four_BE",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Lib.Seqs_s.seq_map",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Seq_s.seq_to_seq_four_BE",
"Vale.Def.Types_s.be_bytes_to_quad32_reveal",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Prims.op_Modulus",
"Prims.l_True",
"Vale.Def.Types_s.be_bytes_to_seq_quad32",
"Vale.Def.Types_s.be_bytes_to_quad32",
"Prims.squash",
"FStar.Seq.Base.create",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let be_bytes_to_seq_quad_of_singleton (q: quad32) (b: seq nat8 {length b == 16})
: Lemma (requires q == be_bytes_to_quad32 b) (ensures create 1 q == be_bytes_to_seq_quad32 b) =
| reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.lemma_reverse_reverse_bytes_nat32_quad32_seq | val lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))] | val lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))] | let lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))]
=
seq_map_inverses reverse_bytes_nat32_quad32 reverse_bytes_nat32_quad32 s | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 74,
"end_line": 596,
"start_col": 0,
"start_line": 592
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
()
let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
()
let lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
=
let s' = reverse_bytes_nat32_quad32 s in
let s''= reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0)); // OBSERVE
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1)); // OBSERVE
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2)); // OBSERVE
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3)); // OBSERVE
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Arch.Types.reverse_bytes_nat32_quad32_seq (Vale.Arch.Types.reverse_bytes_nat32_quad32_seq
s) ==
s)
[
SMTPat (Vale.Arch.Types.reverse_bytes_nat32_quad32_seq (Vale.Arch.Types.reverse_bytes_nat32_quad32_seq
s))
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Vale.Lib.Seqs.seq_map_inverses",
"Vale.Arch.Types.reverse_bytes_nat32_quad32",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.Arch.Types.reverse_bytes_nat32_quad32_seq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let lemma_reverse_reverse_bytes_nat32_quad32_seq (s: seq quad32)
: Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))] =
| seq_map_inverses reverse_bytes_nat32_quad32 reverse_bytes_nat32_quad32 s | false |
Vale.Arch.Types.fst | Vale.Arch.Types.slice_commutes_seq_four_to_seq_BE | val slice_commutes_seq_four_to_seq_BE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) ==
seq_four_to_seq_BE (slice s n n')) | val slice_commutes_seq_four_to_seq_BE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) ==
seq_four_to_seq_BE (slice s n n')) | let slice_commutes_seq_four_to_seq_BE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) ==
seq_four_to_seq_BE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
assert (equal (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4))
(seq_four_to_seq_BE (slice s n n')));
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 630,
"start_col": 0,
"start_line": 623
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
()
let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
()
let lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
=
let s' = reverse_bytes_nat32_quad32 s in
let s''= reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0)); // OBSERVE
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1)); // OBSERVE
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2)); // OBSERVE
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3)); // OBSERVE
()
let lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))]
=
seq_map_inverses reverse_bytes_nat32_quad32 reverse_bytes_nat32_quad32 s
let lemma_reverse_reverse_bytes_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))]
=
seq_map_inverses reverse_bytes_quad32 reverse_bytes_quad32 s
let lemma_le_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (le_seq_quad32_to_bytes s) == (length s) * 16)
=
()
let lemma_be_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == (length s) * 16)
=
()
let slice_commutes_seq_four_to_seq_LE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) ==
seq_four_to_seq_LE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
assert (equal (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
(seq_four_to_seq_LE (slice s n n')));
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Seq.Base.seq (Vale.Def.Words_s.four a) ->
n: Prims.nat{n <= FStar.Seq.Base.length s} ->
n': Prims.nat{n <= n' /\ n' <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_four_to_seq_BE s) (n * 4) (n' * 4) ==
Vale.Def.Words.Seq_s.seq_four_to_seq_BE (FStar.Seq.Base.slice s n n')) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.four",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.l_and",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"FStar.Mul.op_Star",
"FStar.Pervasives.reveal_opaque",
"Prims.eq2",
"Prims.int",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let slice_commutes_seq_four_to_seq_BE
(#a: Type)
(s: seq (four a))
(n: nat{n <= length s})
(n': nat{n <= n' /\ n' <= length s})
: Lemma (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) == seq_four_to_seq_BE (slice s n n')) =
| reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
assert (equal (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4)) (seq_four_to_seq_BE (slice s n n')));
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.seq_to_four_BE_is_seq_to_seq_four_BE | val seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s) | val seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s) | let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 529,
"start_col": 0,
"start_line": 524
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Vale.Def.Words.Seq_s.seq4 a
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.create 1 (Vale.Def.Words.Seq_s.seq_to_four_BE s) ==
Vale.Def.Words.Seq_s.seq_to_seq_four_BE s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Words.Seq_s.seq4",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"Vale.Def.Words_s.four",
"FStar.Seq.Base.create",
"Vale.Def.Words.Seq_s.seq_to_four_BE",
"Vale.Def.Words.Seq_s.seq_to_seq_four_BE",
"FStar.Pervasives.reveal_opaque",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.op_Division",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let seq_to_four_BE_is_seq_to_seq_four_BE (#a: Type) (s: seq4 a)
: Lemma (create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s) =
| reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.slice_commutes_le_seq_quad32_to_bytes0 | val slice_commutes_le_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) 0 (n * 16) ==
le_seq_quad32_to_bytes (slice s 0 n)) | val slice_commutes_le_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) 0 (n * 16) ==
le_seq_quad32_to_bytes (slice s 0 n)) | let slice_commutes_le_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) 0 (n * 16) ==
le_seq_quad32_to_bytes (slice s 0 n))
=
slice_commutes_le_seq_quad32_to_bytes s 0 n | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 668,
"start_col": 0,
"start_line": 664
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
()
let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
()
let lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
=
let s' = reverse_bytes_nat32_quad32 s in
let s''= reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0)); // OBSERVE
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1)); // OBSERVE
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2)); // OBSERVE
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3)); // OBSERVE
()
let lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))]
=
seq_map_inverses reverse_bytes_nat32_quad32 reverse_bytes_nat32_quad32 s
let lemma_reverse_reverse_bytes_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))]
=
seq_map_inverses reverse_bytes_quad32 reverse_bytes_quad32 s
let lemma_le_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (le_seq_quad32_to_bytes s) == (length s) * 16)
=
()
let lemma_be_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == (length s) * 16)
=
()
let slice_commutes_seq_four_to_seq_LE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) ==
seq_four_to_seq_LE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
assert (equal (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
(seq_four_to_seq_LE (slice s n n')));
()
let slice_commutes_seq_four_to_seq_BE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) ==
seq_four_to_seq_BE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
assert (equal (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4))
(seq_four_to_seq_BE (slice s n n')));
()
let slice_commutes_le_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16) ==
le_seq_quad32_to_bytes (slice s n n'))
=
le_seq_quad32_to_bytes_reveal ();
slice_commutes_seq_four_to_seq_LE s n n';
assert (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) == seq_four_to_seq_LE (slice s n n'));
(*
le_seq_quad32_to_bytes (slice s n n') == seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE (slice s n n')));
== seq_four_to_seq_LE (seq_map (nat_to_four 8) (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16)
== slice (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s))) (n * 16) (n' * 16)
== seq_four_to_seq_LE (slice (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) (n * 4) (n' * 4))
*)
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_LE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) in
slice_commutes_seq_four_to_seq_LE s_inner (n * 4) (n' * 4);
()
let slice_commutes_be_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (n * 16) (n' * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s n n')))
=
slice_commutes_seq_four_to_seq_BE s n n';
assert (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) == seq_four_to_seq_BE (slice s n n'));
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_BE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_BE s)) in
slice_commutes_seq_four_to_seq_BE s_inner (n * 4) (n' * 4);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> n: Prims.nat{n <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes s) 0 (n * 16) ==
Vale.Def.Types_s.le_seq_quad32_to_bytes (FStar.Seq.Base.slice s 0 n)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Vale.Arch.Types.slice_commutes_le_seq_quad32_to_bytes",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.Def.Types_s.nat8",
"FStar.Seq.Base.slice",
"Vale.Def.Types_s.le_seq_quad32_to_bytes",
"FStar.Mul.op_Star",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let slice_commutes_le_seq_quad32_to_bytes0 (s: seq quad32) (n: nat{n <= length s})
: Lemma (slice (le_seq_quad32_to_bytes s) 0 (n * 16) == le_seq_quad32_to_bytes (slice s 0 n)) =
| slice_commutes_le_seq_quad32_to_bytes s 0 n | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_uint8_hex_pad | val print_uint8_hex_pad: uint8 -> FStar.All.ML unit | val print_uint8_hex_pad: uint8 -> FStar.All.ML unit | let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 55,
"start_col": 0,
"start_line": 54
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Lib.IntTypes.uint8 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Lib.IntTypes.uint8",
"FStar.IO.print_uint8_hex_pad",
"Lib.RawIntTypes.u8_to_UInt8",
"Prims.unit"
] | [] | false | true | false | false | false | let print_uint8_hex_pad x =
| IO.print_uint8_hex_pad (u8_to_UInt8 x) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_uint8_hex | val print_uint8_hex: uint8 -> FStar.All.ML unit | val print_uint8_hex: uint8 -> FStar.All.ML unit | let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 52,
"start_col": 0,
"start_line": 51
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Lib.IntTypes.uint8 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Lib.IntTypes.uint8",
"FStar.IO.print_uint8",
"Lib.RawIntTypes.u8_to_UInt8",
"Prims.unit"
] | [] | false | true | false | false | false | let print_uint8_hex x =
| IO.print_uint8 (u8_to_UInt8 x) | false |
Vale.Arch.Types.fst | Vale.Arch.Types.be_bytes_to_seq_quad32_to_bytes_one_quad | val be_bytes_to_seq_quad32_to_bytes_one_quad (b:quad32) :
Lemma (be_bytes_to_seq_quad32 (be_quad32_to_bytes b) == create 1 b) | val be_bytes_to_seq_quad32_to_bytes_one_quad (b:quad32) :
Lemma (be_bytes_to_seq_quad32 (be_quad32_to_bytes b) == create 1 b) | let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
} | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 359,
"start_col": 0,
"start_line": 342
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
} | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Types_s.be_bytes_to_seq_quad32 (Vale.Arch.Types.be_quad32_to_bytes b) ==
FStar.Seq.Base.create 1 b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"FStar.Calc.calc_finish",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Vale.Def.Types_s.be_bytes_to_seq_quad32",
"Vale.Arch.Types.be_quad32_to_bytes",
"FStar.Seq.Base.create",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Vale.Def.Words.Seq_s.seq_to_seq_four_BE",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Seq_s.four_to_seq_BE",
"Vale.Lib.Seqs_s.seq_map",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_BE",
"Vale.Def.Words_s.nat8",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.l_True",
"Prims.squash",
"Vale.Def.Words.Seq_s.seq16",
"Vale.Def.Words.Seq.seq_to_seq_four_to_seq_BE",
"Vale.Lib.Seqs.seq_map_inverses",
"Vale.Def.Words.Seq.four_to_seq_BE_is_seq_four_to_seq_BE"
] | [] | false | false | true | false | false | let be_bytes_to_seq_quad32_to_bytes_one_quad b =
| calc ( == ) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
( == ) { reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32 }
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
( == ) { reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes }
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8)
(four_to_seq_BE b))));
( == ) { () }
seq_to_seq_four_BE (seq_map (four_to_nat 8)
(seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
( == ) { seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)) }
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
( == ) { seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b) }
seq_to_seq_four_BE (four_to_seq_BE b);
( == ) { four_to_seq_BE_is_seq_four_to_seq_BE b }
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
( == ) { () }
create 1 b;
} | false |
Vale.Arch.Types.fst | Vale.Arch.Types.slice_commutes_be_seq_quad32_to_bytes | val slice_commutes_be_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (n * 16) (n' * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s n n'))) | val slice_commutes_be_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (n * 16) (n' * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s n n'))) | let slice_commutes_be_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (n * 16) (n' * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s n n')))
=
slice_commutes_seq_four_to_seq_BE s n n';
assert (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) == seq_four_to_seq_BE (slice s n n'));
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_BE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_BE s)) in
slice_commutes_seq_four_to_seq_BE s_inner (n * 4) (n' * 4);
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 662,
"start_col": 0,
"start_line": 652
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
()
let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
()
let lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
=
let s' = reverse_bytes_nat32_quad32 s in
let s''= reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0)); // OBSERVE
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1)); // OBSERVE
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2)); // OBSERVE
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3)); // OBSERVE
()
let lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))]
=
seq_map_inverses reverse_bytes_nat32_quad32 reverse_bytes_nat32_quad32 s
let lemma_reverse_reverse_bytes_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))]
=
seq_map_inverses reverse_bytes_quad32 reverse_bytes_quad32 s
let lemma_le_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (le_seq_quad32_to_bytes s) == (length s) * 16)
=
()
let lemma_be_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == (length s) * 16)
=
()
let slice_commutes_seq_four_to_seq_LE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) ==
seq_four_to_seq_LE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
assert (equal (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
(seq_four_to_seq_LE (slice s n n')));
()
let slice_commutes_seq_four_to_seq_BE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) ==
seq_four_to_seq_BE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
assert (equal (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4))
(seq_four_to_seq_BE (slice s n n')));
()
let slice_commutes_le_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16) ==
le_seq_quad32_to_bytes (slice s n n'))
=
le_seq_quad32_to_bytes_reveal ();
slice_commutes_seq_four_to_seq_LE s n n';
assert (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) == seq_four_to_seq_LE (slice s n n'));
(*
le_seq_quad32_to_bytes (slice s n n') == seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE (slice s n n')));
== seq_four_to_seq_LE (seq_map (nat_to_four 8) (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16)
== slice (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s))) (n * 16) (n' * 16)
== seq_four_to_seq_LE (slice (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) (n * 4) (n' * 4))
*)
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_LE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) in
slice_commutes_seq_four_to_seq_LE s_inner (n * 4) (n' * 4);
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
n: Prims.nat{n <= FStar.Seq.Base.length s} ->
n': Prims.nat{n <= n' /\ n' <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
s))
(n * 16)
(n' * 16) ==
Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE (FStar.Seq.Base.slice
s
n
n'))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.l_and",
"Prims.unit",
"Vale.Arch.Types.slice_commutes_seq_four_to_seq_BE",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words_s.four",
"Vale.Lib.Seqs_s.seq_map",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Lib.Seqs.slice_seq_map_commute",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.slice",
"Prims.l_True",
"Prims.squash",
"Vale.Def.Words_s.nat8",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let slice_commutes_be_seq_quad32_to_bytes
(s: seq quad32)
(n: nat{n <= length s})
(n': nat{n <= n' /\ n' <= length s})
: Lemma
(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (n * 16) (n' * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s n n'))) =
| slice_commutes_seq_four_to_seq_BE s n n';
assert (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) == seq_four_to_seq_BE (slice s n n'));
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_BE s) (n * 4) (n' * 4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_BE s)) in
slice_commutes_seq_four_to_seq_BE s_inner (n * 4) (n' * 4);
() | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_uint32_hex | val print_uint32_hex: uint32 -> FStar.All.ML unit | val print_uint32_hex: uint32 -> FStar.All.ML unit | let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 65,
"start_col": 0,
"start_line": 64
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Lib.IntTypes.uint32 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Lib.IntTypes.uint32",
"FStar.IO.print_uint32",
"Lib.RawIntTypes.u32_to_UInt32",
"Prims.unit"
] | [] | false | true | false | false | false | let print_uint32_hex x =
| IO.print_uint32 (u32_to_UInt32 x) | false |
Vale.Arch.Types.fst | Vale.Arch.Types.slice_commutes_be_seq_quad32_to_bytes0 | val slice_commutes_be_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 (n * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s 0 n))) | val slice_commutes_be_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 (n * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s 0 n))) | let slice_commutes_be_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 (n * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s 0 n)))
=
slice_commutes_be_seq_quad32_to_bytes s 0 n | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 674,
"start_col": 0,
"start_line": 670
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
()
let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
()
let lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
=
let s' = reverse_bytes_nat32_quad32 s in
let s''= reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0)); // OBSERVE
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1)); // OBSERVE
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2)); // OBSERVE
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3)); // OBSERVE
()
let lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))]
=
seq_map_inverses reverse_bytes_nat32_quad32 reverse_bytes_nat32_quad32 s
let lemma_reverse_reverse_bytes_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))]
=
seq_map_inverses reverse_bytes_quad32 reverse_bytes_quad32 s
let lemma_le_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (le_seq_quad32_to_bytes s) == (length s) * 16)
=
()
let lemma_be_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == (length s) * 16)
=
()
let slice_commutes_seq_four_to_seq_LE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) ==
seq_four_to_seq_LE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
assert (equal (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
(seq_four_to_seq_LE (slice s n n')));
()
let slice_commutes_seq_four_to_seq_BE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) ==
seq_four_to_seq_BE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
assert (equal (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4))
(seq_four_to_seq_BE (slice s n n')));
()
let slice_commutes_le_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16) ==
le_seq_quad32_to_bytes (slice s n n'))
=
le_seq_quad32_to_bytes_reveal ();
slice_commutes_seq_four_to_seq_LE s n n';
assert (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) == seq_four_to_seq_LE (slice s n n'));
(*
le_seq_quad32_to_bytes (slice s n n') == seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE (slice s n n')));
== seq_four_to_seq_LE (seq_map (nat_to_four 8) (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16)
== slice (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s))) (n * 16) (n' * 16)
== seq_four_to_seq_LE (slice (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) (n * 4) (n' * 4))
*)
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_LE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) in
slice_commutes_seq_four_to_seq_LE s_inner (n * 4) (n' * 4);
()
let slice_commutes_be_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (n * 16) (n' * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s n n')))
=
slice_commutes_seq_four_to_seq_BE s n n';
assert (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) == seq_four_to_seq_BE (slice s n n'));
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_BE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_BE s)) in
slice_commutes_seq_four_to_seq_BE s_inner (n * 4) (n' * 4);
()
let slice_commutes_le_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) 0 (n * 16) ==
le_seq_quad32_to_bytes (slice s 0 n))
=
slice_commutes_le_seq_quad32_to_bytes s 0 n | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> n: Prims.nat{n <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE
s))
0
(n * 16) ==
Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE (FStar.Seq.Base.slice
s
0
n))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Vale.Arch.Types.slice_commutes_be_seq_quad32_to_bytes",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"Prims.eq2",
"Vale.Def.Words_s.nat8",
"FStar.Seq.Base.slice",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Types_s.nat32",
"FStar.Mul.op_Star",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let slice_commutes_be_seq_quad32_to_bytes0 (s: seq quad32) (n: nat{n <= length s})
: Lemma
(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 (n * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s 0 n))) =
| slice_commutes_be_seq_quad32_to_bytes s 0 n | false |
Vale.Arch.Types.fst | Vale.Arch.Types.slice_commutes_le_seq_quad32_to_bytes | val slice_commutes_le_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16) ==
le_seq_quad32_to_bytes (slice s n n')) | val slice_commutes_le_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16) ==
le_seq_quad32_to_bytes (slice s n n')) | let slice_commutes_le_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16) ==
le_seq_quad32_to_bytes (slice s n n'))
=
le_seq_quad32_to_bytes_reveal ();
slice_commutes_seq_four_to_seq_LE s n n';
assert (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) == seq_four_to_seq_LE (slice s n n'));
(*
le_seq_quad32_to_bytes (slice s n n') == seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE (slice s n n')));
== seq_four_to_seq_LE (seq_map (nat_to_four 8) (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16)
== slice (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s))) (n * 16) (n' * 16)
== seq_four_to_seq_LE (slice (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) (n * 4) (n' * 4))
*)
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_LE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) in
slice_commutes_seq_four_to_seq_LE s_inner (n * 4) (n' * 4);
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 650,
"start_col": 0,
"start_line": 632
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
()
let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
()
let lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
=
let s' = reverse_bytes_nat32_quad32 s in
let s''= reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0)); // OBSERVE
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1)); // OBSERVE
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2)); // OBSERVE
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3)); // OBSERVE
()
let lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))]
=
seq_map_inverses reverse_bytes_nat32_quad32 reverse_bytes_nat32_quad32 s
let lemma_reverse_reverse_bytes_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))]
=
seq_map_inverses reverse_bytes_quad32 reverse_bytes_quad32 s
let lemma_le_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (le_seq_quad32_to_bytes s) == (length s) * 16)
=
()
let lemma_be_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == (length s) * 16)
=
()
let slice_commutes_seq_four_to_seq_LE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) ==
seq_four_to_seq_LE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
assert (equal (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
(seq_four_to_seq_LE (slice s n n')));
()
let slice_commutes_seq_four_to_seq_BE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) ==
seq_four_to_seq_BE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
assert (equal (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4))
(seq_four_to_seq_BE (slice s n n')));
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 ->
n: Prims.nat{n <= FStar.Seq.Base.length s} ->
n': Prims.nat{n <= n' /\ n' <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.slice (Vale.Def.Types_s.le_seq_quad32_to_bytes s) (n * 16) (n' * 16) ==
Vale.Def.Types_s.le_seq_quad32_to_bytes (FStar.Seq.Base.slice s n n')) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.l_and",
"Prims.unit",
"Vale.Arch.Types.slice_commutes_seq_four_to_seq_LE",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words_s.four",
"Vale.Lib.Seqs_s.seq_map",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words.Seq_s.seq_four_to_seq_LE",
"Vale.Lib.Seqs.slice_seq_map_commute",
"Prims._assert",
"Prims.eq2",
"FStar.Seq.Base.slice",
"Vale.Def.Types_s.le_seq_quad32_to_bytes_reveal",
"Prims.l_True",
"Prims.squash",
"Vale.Def.Types_s.nat8",
"Vale.Def.Types_s.le_seq_quad32_to_bytes",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let slice_commutes_le_seq_quad32_to_bytes
(s: seq quad32)
(n: nat{n <= length s})
(n': nat{n <= n' /\ n' <= length s})
: Lemma
(slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16) == le_seq_quad32_to_bytes (slice s n n')) =
| le_seq_quad32_to_bytes_reveal ();
slice_commutes_seq_four_to_seq_LE s n n';
assert (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) == seq_four_to_seq_LE (slice s n n'));
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_LE s) (n * 4) (n' * 4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) in
slice_commutes_seq_four_to_seq_LE s_inner (n * 4) (n' * 4);
() | false |
Vale.Arch.Types.fst | Vale.Arch.Types.slice_commutes_seq_four_to_seq_LE | val slice_commutes_seq_four_to_seq_LE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) ==
seq_four_to_seq_LE (slice s n n')) | val slice_commutes_seq_four_to_seq_LE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) ==
seq_four_to_seq_LE (slice s n n')) | let slice_commutes_seq_four_to_seq_LE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) ==
seq_four_to_seq_LE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
assert (equal (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
(seq_four_to_seq_LE (slice s n n')));
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 621,
"start_col": 0,
"start_line": 614
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
()
let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
()
let lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
=
let s' = reverse_bytes_nat32_quad32 s in
let s''= reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0)); // OBSERVE
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1)); // OBSERVE
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2)); // OBSERVE
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3)); // OBSERVE
()
let lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))]
=
seq_map_inverses reverse_bytes_nat32_quad32 reverse_bytes_nat32_quad32 s
let lemma_reverse_reverse_bytes_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))]
=
seq_map_inverses reverse_bytes_quad32 reverse_bytes_quad32 s
let lemma_le_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (le_seq_quad32_to_bytes s) == (length s) * 16)
=
()
let lemma_be_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == (length s) * 16)
=
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s: FStar.Seq.Base.seq (Vale.Def.Words_s.four a) ->
n: Prims.nat{n <= FStar.Seq.Base.length s} ->
n': Prims.nat{n <= n' /\ n' <= FStar.Seq.Base.length s}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.slice (Vale.Def.Words.Seq_s.seq_four_to_seq_LE s) (n * 4) (n' * 4) ==
Vale.Def.Words.Seq_s.seq_four_to_seq_LE (FStar.Seq.Base.slice s n n')) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.four",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Seq.Base.length",
"Prims.l_and",
"Prims.unit",
"Prims._assert",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"Vale.Def.Words.Seq_s.seq_four_to_seq_LE",
"FStar.Mul.op_Star",
"FStar.Pervasives.reveal_opaque",
"Prims.eq2",
"Prims.int",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let slice_commutes_seq_four_to_seq_LE
(#a: Type)
(s: seq (four a))
(n: nat{n <= length s})
(n': nat{n <= n' /\ n' <= length s})
: Lemma (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) == seq_four_to_seq_LE (slice s n n')) =
| reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
assert (equal (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4)) (seq_four_to_seq_LE (slice s n n')));
() | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_uint8_dec | val print_uint8_dec: uint8 -> FStar.All.ML unit | val print_uint8_dec: uint8 -> FStar.All.ML unit | let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 58,
"start_col": 0,
"start_line": 57
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Lib.IntTypes.uint8 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Lib.IntTypes.uint8",
"FStar.IO.print_uint8_dec",
"Lib.RawIntTypes.u8_to_UInt8",
"Prims.unit"
] | [] | false | true | false | false | false | let print_uint8_dec x =
| IO.print_uint8_dec (u8_to_UInt8 x) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_uint32_hex_pad | val print_uint32_hex_pad: uint32 -> FStar.All.ML unit | val print_uint32_hex_pad: uint32 -> FStar.All.ML unit | let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 68,
"start_col": 0,
"start_line": 67
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Lib.IntTypes.uint32 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Lib.IntTypes.uint32",
"FStar.IO.print_uint32_hex_pad",
"Lib.RawIntTypes.u32_to_UInt32",
"Prims.unit"
] | [] | false | true | false | false | false | let print_uint32_hex_pad x =
| IO.print_uint32_hex_pad (u32_to_UInt32 x) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_uint64_hex | val print_uint64_hex: uint64 -> FStar.All.ML unit | val print_uint64_hex: uint64 -> FStar.All.ML unit | let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 78,
"start_col": 0,
"start_line": 77
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Lib.IntTypes.uint64 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.IO.print_uint64",
"Lib.RawIntTypes.u64_to_UInt64",
"Prims.unit"
] | [] | false | true | false | false | false | let print_uint64_hex x =
| IO.print_uint64 (u64_to_UInt64 x) | false |
Vale.Arch.Types.fst | Vale.Arch.Types.append_distributes_be_bytes_to_seq_quad32 | val append_distributes_be_bytes_to_seq_quad32 (s1:seq nat8 { length s1 % 16 == 0 }) (s2:seq nat8 { length s2 % 16 == 0 }) :
Lemma(be_bytes_to_seq_quad32 (s1 @| s2) == (be_bytes_to_seq_quad32 s1) @| (be_bytes_to_seq_quad32 s2)) | val append_distributes_be_bytes_to_seq_quad32 (s1:seq nat8 { length s1 % 16 == 0 }) (s2:seq nat8 { length s2 % 16 == 0 }) :
Lemma(be_bytes_to_seq_quad32 (s1 @| s2) == (be_bytes_to_seq_quad32 s1) @| (be_bytes_to_seq_quad32 s2)) | let append_distributes_be_bytes_to_seq_quad32 (s1:seq nat8 { length s1 % 16 == 0 }) (s2:seq nat8 { length s2 % 16 == 0 }) :
Lemma(be_bytes_to_seq_quad32 (s1 @| s2) == (be_bytes_to_seq_quad32 s1) @| (be_bytes_to_seq_quad32 s2))
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
let s1' = seq_nat8_to_seq_nat32_BE s1 in
let s2' = seq_nat8_to_seq_nat32_BE s2 in
append_distributes_seq_to_seq_four_BE s1' s2';
append_distributes_seq_map (four_to_nat 8) (seq_to_seq_four_BE s1) (seq_to_seq_four_BE s2);
append_distributes_seq_to_seq_four_BE s1 s2;
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 705,
"start_col": 0,
"start_line": 696
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
()
let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
()
let lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
=
let s' = reverse_bytes_nat32_quad32 s in
let s''= reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0)); // OBSERVE
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1)); // OBSERVE
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2)); // OBSERVE
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3)); // OBSERVE
()
let lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))]
=
seq_map_inverses reverse_bytes_nat32_quad32 reverse_bytes_nat32_quad32 s
let lemma_reverse_reverse_bytes_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))]
=
seq_map_inverses reverse_bytes_quad32 reverse_bytes_quad32 s
let lemma_le_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (le_seq_quad32_to_bytes s) == (length s) * 16)
=
()
let lemma_be_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == (length s) * 16)
=
()
let slice_commutes_seq_four_to_seq_LE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) ==
seq_four_to_seq_LE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
assert (equal (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
(seq_four_to_seq_LE (slice s n n')));
()
let slice_commutes_seq_four_to_seq_BE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) ==
seq_four_to_seq_BE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
assert (equal (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4))
(seq_four_to_seq_BE (slice s n n')));
()
let slice_commutes_le_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16) ==
le_seq_quad32_to_bytes (slice s n n'))
=
le_seq_quad32_to_bytes_reveal ();
slice_commutes_seq_four_to_seq_LE s n n';
assert (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) == seq_four_to_seq_LE (slice s n n'));
(*
le_seq_quad32_to_bytes (slice s n n') == seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE (slice s n n')));
== seq_four_to_seq_LE (seq_map (nat_to_four 8) (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16)
== slice (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s))) (n * 16) (n' * 16)
== seq_four_to_seq_LE (slice (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) (n * 4) (n' * 4))
*)
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_LE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) in
slice_commutes_seq_four_to_seq_LE s_inner (n * 4) (n' * 4);
()
let slice_commutes_be_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (n * 16) (n' * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s n n')))
=
slice_commutes_seq_four_to_seq_BE s n n';
assert (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) == seq_four_to_seq_BE (slice s n n'));
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_BE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_BE s)) in
slice_commutes_seq_four_to_seq_BE s_inner (n * 4) (n' * 4);
()
let slice_commutes_le_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) 0 (n * 16) ==
le_seq_quad32_to_bytes (slice s 0 n))
=
slice_commutes_le_seq_quad32_to_bytes s 0 n
let slice_commutes_be_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 (n * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s 0 n)))
=
slice_commutes_be_seq_quad32_to_bytes s 0 n
#reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let append_distributes_le_bytes_to_seq_quad32 (s1:seq nat8 { length s1 % 16 == 0 }) (s2:seq nat8 { length s2 % 16 == 0 }) :
Lemma(le_bytes_to_seq_quad32 (s1 @| s2) == (le_bytes_to_seq_quad32 s1) @| (le_bytes_to_seq_quad32 s2))
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
let s1' = seq_nat8_to_seq_nat32_LE s1 in
let s2' = seq_nat8_to_seq_nat32_LE s2 in
// (le_bytes_to_seq_quad32 s1) @| (le_bytes_to_seq_quad32 s2))
// = { Definition of le_bytes_to_seq_quad32 }
// seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s1) @| seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s2)
append_distributes_seq_to_seq_four_LE s1' s2';
// =
// seq_to_seq_four_LE ((seq_nat8_to_seq_nat32_LE s1) @| (seq_nat8_to_seq_nat32_LE s2))
append_distributes_seq_map (four_to_nat 8) (seq_to_seq_four_LE s1) (seq_to_seq_four_LE s2);
// seq_to_seq_four_LE (seq_map (four_to_nat 8) ((seq_to_seq_four_LE s1) @| (seq_to_seq_four_LE s2)))
append_distributes_seq_to_seq_four_LE s1 s2;
// seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (s1 @| s2)))
// le_bytes_to_seq_quad32 (s1 @| s2)
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s1: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length s1 % 16 == 0} ->
s2: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length s2 % 16 == 0}
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Types_s.be_bytes_to_seq_quad32 (s1 @| s2) ==
Vale.Def.Types_s.be_bytes_to_seq_quad32 s1 @| Vale.Def.Types_s.be_bytes_to_seq_quad32 s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.unit",
"Vale.Def.Words.Seq.append_distributes_seq_to_seq_four_BE",
"Vale.Lib.Seqs.append_distributes_seq_map",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Seq_s.seq_to_seq_four_BE",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_BE",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Vale.Def.Types_s.quad32",
"Prims.l_True",
"Vale.Def.Types_s.be_bytes_to_seq_quad32",
"Prims.squash",
"FStar.Seq.Base.op_At_Bar",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let append_distributes_be_bytes_to_seq_quad32
(s1: seq nat8 {length s1 % 16 == 0})
(s2: seq nat8 {length s2 % 16 == 0})
: Lemma
(be_bytes_to_seq_quad32 (s1 @| s2) == (be_bytes_to_seq_quad32 s1) @| (be_bytes_to_seq_quad32 s2)
) =
| reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
let s1' = seq_nat8_to_seq_nat32_BE s1 in
let s2' = seq_nat8_to_seq_nat32_BE s2 in
append_distributes_seq_to_seq_four_BE s1' s2';
append_distributes_seq_map (four_to_nat 8) (seq_to_seq_four_BE s1) (seq_to_seq_four_BE s2);
append_distributes_seq_to_seq_four_BE s1 s2;
() | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_uint8_dec_pad | val print_uint8_dec_pad: uint8 -> FStar.All.ML unit | val print_uint8_dec_pad: uint8 -> FStar.All.ML unit | let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 40,
"end_line": 61,
"start_col": 0,
"start_line": 60
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Lib.IntTypes.uint8 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Lib.IntTypes.uint8",
"FStar.IO.print_uint8_dec_pad",
"Lib.RawIntTypes.u8_to_UInt8",
"Prims.unit"
] | [] | false | true | false | false | false | let print_uint8_dec_pad x =
| IO.print_uint8_dec_pad (u8_to_UInt8 x) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_nat8_hex_pad | val print_nat8_hex_pad: x:nat{x <= maxint U8} -> FStar.All.ML unit | val print_nat8_hex_pad: x:nat{x <= maxint U8} -> FStar.All.ML unit | let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x)) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 16,
"start_col": 0,
"start_line": 15
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Prims.nat{x <= Lib.IntTypes.maxint Lib.IntTypes.U8} -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.maxint",
"Lib.IntTypes.U8",
"FStar.IO.print_uint8_hex_pad",
"Lib.RawIntTypes.u8_to_UInt8",
"Lib.IntTypes.u8",
"Prims.unit"
] | [] | false | true | false | false | false | let print_nat8_hex_pad x =
| IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x)) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_uint32_dec | val print_uint32_dec: uint32 -> FStar.All.ML unit | val print_uint32_dec: uint32 -> FStar.All.ML unit | let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 71,
"start_col": 0,
"start_line": 70
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Lib.IntTypes.uint32 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Lib.IntTypes.uint32",
"FStar.IO.print_uint32_dec",
"Lib.RawIntTypes.u32_to_UInt32",
"Prims.unit"
] | [] | false | true | false | false | false | let print_uint32_dec x =
| IO.print_uint32_dec (u32_to_UInt32 x) | false |
Vale.Arch.Types.fst | Vale.Arch.Types.le_quad32_to_bytes_to_quad32 | val le_quad32_to_bytes_to_quad32 (s:seq nat8 { length s == 16 }) :
Lemma(le_quad32_to_bytes (le_bytes_to_quad32 s) == s) | val le_quad32_to_bytes_to_quad32 (s:seq nat8 { length s == 16 }) :
Lemma(le_quad32_to_bytes (le_bytes_to_quad32 s) == s) | let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
} | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 423,
"start_col": 0,
"start_line": 410
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*) | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length s == 16}
-> FStar.Pervasives.Lemma
(ensures Vale.Def.Types_s.le_quad32_to_bytes (Vale.Def.Types_s.le_bytes_to_quad32 s) == s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"FStar.Calc.calc_finish",
"Vale.Def.Types_s.nat8",
"Vale.Def.Types_s.le_quad32_to_bytes",
"Vale.Def.Types_s.le_bytes_to_quad32",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Vale.Def.Words.Seq_s.seq_four_to_seq_LE",
"Vale.Def.Words.Seq_s.seq_to_seq_four_LE",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Lib.Seqs_s.seq_map",
"FStar.Mul.op_Star",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Seq_s.four_to_seq_LE",
"Vale.Def.Words.Seq_s.seq_to_four_LE",
"Vale.Def.Types_s.nat32",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Vale.Def.Types_s.le_bytes_to_quad32_reveal",
"Prims.squash",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.quad32",
"Prims.l_True",
"Vale.Def.Words.Seq.four_to_seq_to_four_LE",
"Vale.Lib.Seqs.seq_map_inverses"
] | [] | false | false | true | false | false | let le_quad32_to_bytes_to_quad32 s =
| calc ( == ) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
( == ) { le_bytes_to_quad32_reveal () }
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
( == ) { reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8)
(four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
( == ) { four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)) }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
( == ) { seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s) }
seq_four_to_seq_LE (seq_to_seq_four_LE s);
( == ) { () }
s;
} | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_uint32_dec_pad | val print_uint32_dec_pad: uint32 -> FStar.All.ML unit | val print_uint32_dec_pad: uint32 -> FStar.All.ML unit | let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 74,
"start_col": 0,
"start_line": 73
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Lib.IntTypes.uint32 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Lib.IntTypes.uint32",
"FStar.IO.print_uint32_dec_pad",
"Lib.RawIntTypes.u32_to_UInt32",
"Prims.unit"
] | [] | false | true | false | false | false | let print_uint32_dec_pad x =
| IO.print_uint32_dec_pad (u32_to_UInt32 x) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_uint64_dec_pad | val print_uint64_dec_pad: uint64 -> FStar.All.ML unit | val print_uint64_dec_pad: uint64 -> FStar.All.ML unit | let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 87,
"start_col": 0,
"start_line": 86
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Lib.IntTypes.uint64 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.IO.print_uint64_dec_pad",
"Lib.RawIntTypes.u64_to_UInt64",
"Prims.unit"
] | [] | false | true | false | false | false | let print_uint64_dec_pad x =
| IO.print_uint64_dec_pad (u64_to_UInt64 x) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_uint64_hex_pad | val print_uint64_hex_pad: uint64 -> FStar.All.ML unit | val print_uint64_hex_pad: uint64 -> FStar.All.ML unit | let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 81,
"start_col": 0,
"start_line": 80
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Lib.IntTypes.uint64 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.IO.print_uint64_hex_pad",
"Lib.RawIntTypes.u64_to_UInt64",
"Prims.unit"
] | [] | false | true | false | false | false | let print_uint64_hex_pad x =
| IO.print_uint64_hex_pad (u64_to_UInt64 x) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_label_nat64 | val print_label_nat64: display:bool -> string -> x:nat{x <= maxint U64} -> FStar.All.ML unit | val print_label_nat64: display:bool -> string -> x:nat{x <= maxint U64} -> FStar.All.ML unit | let print_label_nat64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n") | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 95,
"start_col": 0,
"start_line": 90
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x)
let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | display: Prims.bool -> s: Prims.string -> x: Prims.nat{x <= Lib.IntTypes.maxint Lib.IntTypes.U64}
-> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Prims.string",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.maxint",
"Lib.IntTypes.U64",
"Prims.op_Negation",
"Prims.unit",
"FStar.IO.print_string",
"Lib.PrintSequence.print_nat64_dec"
] | [] | false | true | false | false | false | let print_label_nat64 flag s x =
| if not flag
then ()
else
(IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n") | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_nat8_hex | val print_nat8_hex: x:nat{x <= maxint U8} -> FStar.All.ML unit | val print_nat8_hex: x:nat{x <= maxint U8} -> FStar.All.ML unit | let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x)) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 13,
"start_col": 0,
"start_line": 12
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Prims.nat{x <= Lib.IntTypes.maxint Lib.IntTypes.U8} -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.maxint",
"Lib.IntTypes.U8",
"FStar.IO.print_uint8",
"Lib.RawIntTypes.u8_to_UInt8",
"Lib.IntTypes.u8",
"Prims.unit"
] | [] | false | true | false | false | false | let print_nat8_hex x =
| IO.print_uint8 (u8_to_UInt8 (u8 x)) | false |
Vale.Arch.Types.fst | Vale.Arch.Types.le_bytes_to_seq_quad32_to_bytes_one_quad | val le_bytes_to_seq_quad32_to_bytes_one_quad (b:quad32) :
Lemma (le_bytes_to_seq_quad32 (le_quad32_to_bytes b) == create 1 b) | val le_bytes_to_seq_quad32_to_bytes_one_quad (b:quad32) :
Lemma (le_bytes_to_seq_quad32 (le_quad32_to_bytes b) == create 1 b) | let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
} | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 340,
"start_col": 0,
"start_line": 323
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Types_s.le_bytes_to_seq_quad32 (Vale.Def.Types_s.le_quad32_to_bytes b) ==
FStar.Seq.Base.create 1 b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"FStar.Calc.calc_finish",
"FStar.Seq.Base.seq",
"Prims.eq2",
"Vale.Def.Types_s.le_bytes_to_seq_quad32",
"Vale.Def.Types_s.le_quad32_to_bytes",
"FStar.Seq.Base.create",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Vale.Def.Words.Seq_s.seq_to_seq_four_LE",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words.Seq_s.seq_four_to_seq_LE",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Seq_s.four_to_seq_LE",
"Vale.Lib.Seqs_s.seq_map",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE",
"Vale.Def.Words_s.nat8",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.l_True",
"Prims.squash",
"Vale.Def.Words.Seq.seq_to_seq_four_to_seq_LE",
"Vale.Lib.Seqs.seq_map_inverses",
"Vale.Def.Words.Seq.four_to_seq_LE_is_seq_four_to_seq_LE"
] | [] | false | false | true | false | false | let le_bytes_to_seq_quad32_to_bytes_one_quad b =
| calc ( == ) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
( == ) { reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
( == ) { reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8)
(four_to_seq_LE b))));
( == ) { () }
seq_to_seq_four_LE (seq_map (four_to_nat 8)
(seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
( == ) { seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)) }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
( == ) { seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b) }
seq_to_seq_four_LE (four_to_seq_LE b);
( == ) { four_to_seq_LE_is_seq_four_to_seq_LE b }
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
( == ) { () }
create 1 b;
} | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_string | val print_string: display:bool -> string -> FStar.All.ML unit | val print_string: display:bool -> string -> FStar.All.ML unit | let print_string flag s = if flag then IO.print_string s else () | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 128,
"start_col": 0,
"start_line": 128
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x)
let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x)
let print_label_nat64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n")
let print_label_uint8 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint8_hex_pad x;
IO.print_string "\n")
let print_label_uint32 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint32_hex_pad x;
IO.print_string "\n")
let print_label_uint64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint64_hex_pad x;
IO.print_string "\n")
let print_list_nat64 flag l =
if not flag then ()
else (
repeat_range_all_ml 0 (List.Tot.length l) (fun i _ ->
print_nat64_dec (List.Tot.index l i);
IO.print_string " "
) ()) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | display: Prims.bool -> s: Prims.string -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Prims.string",
"FStar.IO.print_string",
"Prims.unit"
] | [] | false | true | false | false | false | let print_string flag s =
| if flag then IO.print_string s | false |
Vale.Arch.Types.fst | Vale.Arch.Types.append_distributes_be_seq_quad32_to_bytes | val append_distributes_be_seq_quad32_to_bytes (s1:seq quad32) (s2:seq quad32) :
Lemma(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (s1 @| s2)) == (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s1)) @| (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s2))) | val append_distributes_be_seq_quad32_to_bytes (s1:seq quad32) (s2:seq quad32) :
Lemma(seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (s1 @| s2)) == (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s1)) @| (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s2))) | let append_distributes_be_seq_quad32_to_bytes s1 s2 =
calc (==) {
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (s1 @| s2));
(==) { }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (s1 @| s2));
(==) { append_distributes_seq_four_to_seq_BE s1 s2 }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s1 @| seq_four_to_seq_BE s2);
(==) { append_distributes_seq_map (nat_to_four 8) (seq_four_to_seq_BE s1) (seq_four_to_seq_BE s2) }
seq_four_to_seq_BE (
seq_map (nat_to_four 8) (seq_four_to_seq_BE s1) @|
seq_map (nat_to_four 8) (seq_four_to_seq_BE s2));
(==) { append_distributes_seq_four_to_seq_BE
(seq_map (nat_to_four 8) (seq_four_to_seq_BE s1))
(seq_map (nat_to_four 8) (seq_four_to_seq_BE s2)) }
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s1)) @|
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s2));
(==) { }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s1) @| seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s2);
} | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 746,
"start_col": 0,
"start_line": 728
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
()
let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
()
let lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
=
let s' = reverse_bytes_nat32_quad32 s in
let s''= reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0)); // OBSERVE
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1)); // OBSERVE
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2)); // OBSERVE
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3)); // OBSERVE
()
let lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))]
=
seq_map_inverses reverse_bytes_nat32_quad32 reverse_bytes_nat32_quad32 s
let lemma_reverse_reverse_bytes_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))]
=
seq_map_inverses reverse_bytes_quad32 reverse_bytes_quad32 s
let lemma_le_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (le_seq_quad32_to_bytes s) == (length s) * 16)
=
()
let lemma_be_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == (length s) * 16)
=
()
let slice_commutes_seq_four_to_seq_LE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) ==
seq_four_to_seq_LE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
assert (equal (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
(seq_four_to_seq_LE (slice s n n')));
()
let slice_commutes_seq_four_to_seq_BE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) ==
seq_four_to_seq_BE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
assert (equal (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4))
(seq_four_to_seq_BE (slice s n n')));
()
let slice_commutes_le_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16) ==
le_seq_quad32_to_bytes (slice s n n'))
=
le_seq_quad32_to_bytes_reveal ();
slice_commutes_seq_four_to_seq_LE s n n';
assert (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) == seq_four_to_seq_LE (slice s n n'));
(*
le_seq_quad32_to_bytes (slice s n n') == seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE (slice s n n')));
== seq_four_to_seq_LE (seq_map (nat_to_four 8) (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16)
== slice (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s))) (n * 16) (n' * 16)
== seq_four_to_seq_LE (slice (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) (n * 4) (n' * 4))
*)
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_LE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) in
slice_commutes_seq_four_to_seq_LE s_inner (n * 4) (n' * 4);
()
let slice_commutes_be_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (n * 16) (n' * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s n n')))
=
slice_commutes_seq_four_to_seq_BE s n n';
assert (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) == seq_four_to_seq_BE (slice s n n'));
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_BE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_BE s)) in
slice_commutes_seq_four_to_seq_BE s_inner (n * 4) (n' * 4);
()
let slice_commutes_le_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) 0 (n * 16) ==
le_seq_quad32_to_bytes (slice s 0 n))
=
slice_commutes_le_seq_quad32_to_bytes s 0 n
let slice_commutes_be_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 (n * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s 0 n)))
=
slice_commutes_be_seq_quad32_to_bytes s 0 n
#reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let append_distributes_le_bytes_to_seq_quad32 (s1:seq nat8 { length s1 % 16 == 0 }) (s2:seq nat8 { length s2 % 16 == 0 }) :
Lemma(le_bytes_to_seq_quad32 (s1 @| s2) == (le_bytes_to_seq_quad32 s1) @| (le_bytes_to_seq_quad32 s2))
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
let s1' = seq_nat8_to_seq_nat32_LE s1 in
let s2' = seq_nat8_to_seq_nat32_LE s2 in
// (le_bytes_to_seq_quad32 s1) @| (le_bytes_to_seq_quad32 s2))
// = { Definition of le_bytes_to_seq_quad32 }
// seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s1) @| seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s2)
append_distributes_seq_to_seq_four_LE s1' s2';
// =
// seq_to_seq_four_LE ((seq_nat8_to_seq_nat32_LE s1) @| (seq_nat8_to_seq_nat32_LE s2))
append_distributes_seq_map (four_to_nat 8) (seq_to_seq_four_LE s1) (seq_to_seq_four_LE s2);
// seq_to_seq_four_LE (seq_map (four_to_nat 8) ((seq_to_seq_four_LE s1) @| (seq_to_seq_four_LE s2)))
append_distributes_seq_to_seq_four_LE s1 s2;
// seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (s1 @| s2)))
// le_bytes_to_seq_quad32 (s1 @| s2)
()
let append_distributes_be_bytes_to_seq_quad32 (s1:seq nat8 { length s1 % 16 == 0 }) (s2:seq nat8 { length s2 % 16 == 0 }) :
Lemma(be_bytes_to_seq_quad32 (s1 @| s2) == (be_bytes_to_seq_quad32 s1) @| (be_bytes_to_seq_quad32 s2))
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
let s1' = seq_nat8_to_seq_nat32_BE s1 in
let s2' = seq_nat8_to_seq_nat32_BE s2 in
append_distributes_seq_to_seq_four_BE s1' s2';
append_distributes_seq_map (four_to_nat 8) (seq_to_seq_four_BE s1) (seq_to_seq_four_BE s2);
append_distributes_seq_to_seq_four_BE s1 s2;
()
let append_distributes_le_seq_quad32_to_bytes s1 s2 =
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (s1 @| s2);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (s1 @| s2));
(==) { append_distributes_seq_four_to_seq_LE s1 s2 }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s1 @| seq_four_to_seq_LE s2);
(==) { append_distributes_seq_map (nat_to_four 8) (seq_four_to_seq_LE s1) (seq_four_to_seq_LE s2) }
seq_four_to_seq_LE (
seq_map (nat_to_four 8) (seq_four_to_seq_LE s1) @|
seq_map (nat_to_four 8) (seq_four_to_seq_LE s2));
(==) { append_distributes_seq_four_to_seq_LE
(seq_map (nat_to_four 8) (seq_four_to_seq_LE s1))
(seq_map (nat_to_four 8) (seq_four_to_seq_LE s2)) }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s1)) @|
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s2));
(==) { }
le_seq_quad32_to_bytes s1 @| le_seq_quad32_to_bytes s2;
} | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> s2: FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE (s1 @|
s2)) ==
Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE s1) @|
Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE (Vale.Def.Words.Seq_s.seq_four_to_seq_BE s2)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"FStar.Calc.calc_finish",
"Vale.Def.Words_s.nat8",
"Prims.eq2",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_BE",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Types_s.nat32",
"FStar.Seq.Base.op_At_Bar",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Lib.Seqs_s.seq_map",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Four_s.nat_to_four",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"Vale.Def.Words.Seq.append_distributes_seq_four_to_seq_BE",
"Vale.Lib.Seqs.append_distributes_seq_map"
] | [] | false | false | true | false | false | let append_distributes_be_seq_quad32_to_bytes s1 s2 =
| calc ( == ) {
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (s1 @| s2));
( == ) { () }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (s1 @| s2));
( == ) { append_distributes_seq_four_to_seq_BE s1 s2 }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s1 @| seq_four_to_seq_BE s2);
( == ) { append_distributes_seq_map (nat_to_four 8)
(seq_four_to_seq_BE s1)
(seq_four_to_seq_BE s2) }
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s1) @|
seq_map (nat_to_four 8) (seq_four_to_seq_BE s2));
( == ) { append_distributes_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s1))
(seq_map (nat_to_four 8) (seq_four_to_seq_BE s2)) }
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s1)) @|
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s2));
( == ) { () }
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s1) @|
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s2);
} | false |
Vale.Arch.Types.fst | Vale.Arch.Types.be_quad32_to_bytes_to_quad32 | val be_quad32_to_bytes_to_quad32 (s:seq nat8 { length s == 16 }) :
Lemma(be_quad32_to_bytes (be_bytes_to_quad32 s) == s) | val be_quad32_to_bytes_to_quad32 (s:seq nat8 { length s == 16 }) :
Lemma(be_quad32_to_bytes (be_bytes_to_quad32 s) == s) | let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
} | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 438,
"start_col": 0,
"start_line": 425
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
} | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 10,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length s == 16}
-> FStar.Pervasives.Lemma
(ensures Vale.Arch.Types.be_quad32_to_bytes (Vale.Def.Types_s.be_bytes_to_quad32 s) == s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Prims.eq2",
"Prims.int",
"FStar.Seq.Base.length",
"FStar.Calc.calc_finish",
"Vale.Def.Words.Seq_s.seq16",
"Vale.Arch.Types.be_quad32_to_bytes",
"Vale.Def.Types_s.be_bytes_to_quad32",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Vale.Def.Words.Seq_s.seq_four_to_seq_BE",
"Vale.Def.Words.Seq_s.seq_to_seq_four_BE",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Lib.Seqs_s.seq_map",
"FStar.Mul.op_Star",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Seq_s.four_to_seq_BE",
"Vale.Def.Words.Seq_s.seq_to_four_BE",
"Vale.Def.Types_s.nat32",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Vale.Def.Types_s.be_bytes_to_quad32_reveal",
"Prims.squash",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.quad32",
"Vale.Def.Words.Seq.four_to_seq_to_four_BE",
"Vale.Lib.Seqs.seq_map_inverses"
] | [] | false | false | true | false | false | let be_quad32_to_bytes_to_quad32 s =
| calc ( == ) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
( == ) { be_bytes_to_quad32_reveal () }
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
( == ) { reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes }
seq_four_to_seq_BE (seq_map (nat_to_four 8)
(four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
( == ) { four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)) }
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
( == ) { seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s) }
seq_four_to_seq_BE (seq_to_seq_four_BE s);
( == ) { () }
s;
} | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_label_uint8 | val print_label_uint8: display:bool -> string -> uint8 -> FStar.All.ML unit | val print_label_uint8: display:bool -> string -> uint8 -> FStar.All.ML unit | let print_label_uint8 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint8_hex_pad x;
IO.print_string "\n") | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 102,
"start_col": 0,
"start_line": 97
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x)
let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x)
let print_label_nat64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n") | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | display: Prims.bool -> s: Prims.string -> x: Lib.IntTypes.uint8 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Prims.string",
"Lib.IntTypes.uint8",
"Prims.op_Negation",
"Prims.unit",
"FStar.IO.print_string",
"Lib.PrintSequence.print_uint8_hex_pad"
] | [] | false | true | false | false | false | let print_label_uint8 flag s x =
| if not flag
then ()
else
(IO.print_string s;
IO.print_string ": ";
print_uint8_hex_pad x;
IO.print_string "\n") | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_label_uint32 | val print_label_uint32: display:bool -> string -> uint32 -> FStar.All.ML unit | val print_label_uint32: display:bool -> string -> uint32 -> FStar.All.ML unit | let print_label_uint32 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint32_hex_pad x;
IO.print_string "\n") | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 109,
"start_col": 0,
"start_line": 104
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x)
let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x)
let print_label_nat64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n")
let print_label_uint8 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint8_hex_pad x;
IO.print_string "\n") | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | display: Prims.bool -> s: Prims.string -> x: Lib.IntTypes.uint32 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Prims.string",
"Lib.IntTypes.uint32",
"Prims.op_Negation",
"Prims.unit",
"FStar.IO.print_string",
"Lib.PrintSequence.print_uint32_hex_pad"
] | [] | false | true | false | false | false | let print_label_uint32 flag s x =
| if not flag
then ()
else
(IO.print_string s;
IO.print_string ": ";
print_uint32_hex_pad x;
IO.print_string "\n") | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_label_uint64 | val print_label_uint64: display:bool -> string -> uint64 -> FStar.All.ML unit | val print_label_uint64: display:bool -> string -> uint64 -> FStar.All.ML unit | let print_label_uint64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint64_hex_pad x;
IO.print_string "\n") | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 116,
"start_col": 0,
"start_line": 111
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x)
let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x)
let print_label_nat64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n")
let print_label_uint8 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint8_hex_pad x;
IO.print_string "\n")
let print_label_uint32 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint32_hex_pad x;
IO.print_string "\n") | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | display: Prims.bool -> s: Prims.string -> x: Lib.IntTypes.uint64 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Prims.string",
"Lib.IntTypes.uint64",
"Prims.op_Negation",
"Prims.unit",
"FStar.IO.print_string",
"Lib.PrintSequence.print_uint64_hex_pad"
] | [] | false | true | false | false | false | let print_label_uint64 flag s x =
| if not flag
then ()
else
(IO.print_string s;
IO.print_string ": ";
print_uint64_hex_pad x;
IO.print_string "\n") | false |
Vale.Arch.Types.fst | Vale.Arch.Types.append_distributes_le_seq_quad32_to_bytes | val append_distributes_le_seq_quad32_to_bytes (s1:seq quad32) (s2:seq quad32) :
Lemma(le_seq_quad32_to_bytes (s1 @| s2) == (le_seq_quad32_to_bytes s1) @| (le_seq_quad32_to_bytes s2)) | val append_distributes_le_seq_quad32_to_bytes (s1:seq quad32) (s2:seq quad32) :
Lemma(le_seq_quad32_to_bytes (s1 @| s2) == (le_seq_quad32_to_bytes s1) @| (le_seq_quad32_to_bytes s2)) | let append_distributes_le_seq_quad32_to_bytes s1 s2 =
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (s1 @| s2);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (s1 @| s2));
(==) { append_distributes_seq_four_to_seq_LE s1 s2 }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s1 @| seq_four_to_seq_LE s2);
(==) { append_distributes_seq_map (nat_to_four 8) (seq_four_to_seq_LE s1) (seq_four_to_seq_LE s2) }
seq_four_to_seq_LE (
seq_map (nat_to_four 8) (seq_four_to_seq_LE s1) @|
seq_map (nat_to_four 8) (seq_four_to_seq_LE s2));
(==) { append_distributes_seq_four_to_seq_LE
(seq_map (nat_to_four 8) (seq_four_to_seq_LE s1))
(seq_map (nat_to_four 8) (seq_four_to_seq_LE s2)) }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s1)) @|
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s2));
(==) { }
le_seq_quad32_to_bytes s1 @| le_seq_quad32_to_bytes s2;
} | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 726,
"start_col": 0,
"start_line": 707
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
()
let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
()
let lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
=
let s' = reverse_bytes_nat32_quad32 s in
let s''= reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0)); // OBSERVE
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1)); // OBSERVE
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2)); // OBSERVE
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3)); // OBSERVE
()
let lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))]
=
seq_map_inverses reverse_bytes_nat32_quad32 reverse_bytes_nat32_quad32 s
let lemma_reverse_reverse_bytes_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))]
=
seq_map_inverses reverse_bytes_quad32 reverse_bytes_quad32 s
let lemma_le_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (le_seq_quad32_to_bytes s) == (length s) * 16)
=
()
let lemma_be_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == (length s) * 16)
=
()
let slice_commutes_seq_four_to_seq_LE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) ==
seq_four_to_seq_LE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
assert (equal (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
(seq_four_to_seq_LE (slice s n n')));
()
let slice_commutes_seq_four_to_seq_BE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) ==
seq_four_to_seq_BE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
assert (equal (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4))
(seq_four_to_seq_BE (slice s n n')));
()
let slice_commutes_le_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16) ==
le_seq_quad32_to_bytes (slice s n n'))
=
le_seq_quad32_to_bytes_reveal ();
slice_commutes_seq_four_to_seq_LE s n n';
assert (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) == seq_four_to_seq_LE (slice s n n'));
(*
le_seq_quad32_to_bytes (slice s n n') == seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE (slice s n n')));
== seq_four_to_seq_LE (seq_map (nat_to_four 8) (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16)
== slice (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s))) (n * 16) (n' * 16)
== seq_four_to_seq_LE (slice (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) (n * 4) (n' * 4))
*)
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_LE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) in
slice_commutes_seq_four_to_seq_LE s_inner (n * 4) (n' * 4);
()
let slice_commutes_be_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (n * 16) (n' * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s n n')))
=
slice_commutes_seq_four_to_seq_BE s n n';
assert (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) == seq_four_to_seq_BE (slice s n n'));
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_BE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_BE s)) in
slice_commutes_seq_four_to_seq_BE s_inner (n * 4) (n' * 4);
()
let slice_commutes_le_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) 0 (n * 16) ==
le_seq_quad32_to_bytes (slice s 0 n))
=
slice_commutes_le_seq_quad32_to_bytes s 0 n
let slice_commutes_be_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 (n * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s 0 n)))
=
slice_commutes_be_seq_quad32_to_bytes s 0 n
#reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let append_distributes_le_bytes_to_seq_quad32 (s1:seq nat8 { length s1 % 16 == 0 }) (s2:seq nat8 { length s2 % 16 == 0 }) :
Lemma(le_bytes_to_seq_quad32 (s1 @| s2) == (le_bytes_to_seq_quad32 s1) @| (le_bytes_to_seq_quad32 s2))
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
let s1' = seq_nat8_to_seq_nat32_LE s1 in
let s2' = seq_nat8_to_seq_nat32_LE s2 in
// (le_bytes_to_seq_quad32 s1) @| (le_bytes_to_seq_quad32 s2))
// = { Definition of le_bytes_to_seq_quad32 }
// seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s1) @| seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s2)
append_distributes_seq_to_seq_four_LE s1' s2';
// =
// seq_to_seq_four_LE ((seq_nat8_to_seq_nat32_LE s1) @| (seq_nat8_to_seq_nat32_LE s2))
append_distributes_seq_map (four_to_nat 8) (seq_to_seq_four_LE s1) (seq_to_seq_four_LE s2);
// seq_to_seq_four_LE (seq_map (four_to_nat 8) ((seq_to_seq_four_LE s1) @| (seq_to_seq_four_LE s2)))
append_distributes_seq_to_seq_four_LE s1 s2;
// seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (s1 @| s2)))
// le_bytes_to_seq_quad32 (s1 @| s2)
()
let append_distributes_be_bytes_to_seq_quad32 (s1:seq nat8 { length s1 % 16 == 0 }) (s2:seq nat8 { length s2 % 16 == 0 }) :
Lemma(be_bytes_to_seq_quad32 (s1 @| s2) == (be_bytes_to_seq_quad32 s1) @| (be_bytes_to_seq_quad32 s2))
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
let s1' = seq_nat8_to_seq_nat32_BE s1 in
let s2' = seq_nat8_to_seq_nat32_BE s2 in
append_distributes_seq_to_seq_four_BE s1' s2';
append_distributes_seq_map (four_to_nat 8) (seq_to_seq_four_BE s1) (seq_to_seq_four_BE s2);
append_distributes_seq_to_seq_four_BE s1 s2;
() | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s1: FStar.Seq.Base.seq Vale.Def.Types_s.quad32 -> s2: FStar.Seq.Base.seq Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Types_s.le_seq_quad32_to_bytes (s1 @| s2) ==
Vale.Def.Types_s.le_seq_quad32_to_bytes s1 @| Vale.Def.Types_s.le_seq_quad32_to_bytes s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Types_s.quad32",
"FStar.Calc.calc_finish",
"Vale.Def.Types_s.nat8",
"Prims.eq2",
"Vale.Def.Types_s.le_seq_quad32_to_bytes",
"FStar.Seq.Base.op_At_Bar",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Seq_s.seq_four_to_seq_LE",
"Vale.Lib.Seqs_s.seq_map",
"Vale.Def.Types_s.nat32",
"Vale.Def.Words_s.four",
"Vale.Def.Words.Four_s.nat_to_four",
"Vale.Def.Words.Seq_s.seq_nat32_to_seq_nat8_LE",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"Vale.Def.Words.Seq.append_distributes_seq_four_to_seq_LE",
"Vale.Lib.Seqs.append_distributes_seq_map",
"Vale.Def.Types_s.le_seq_quad32_to_bytes_reveal"
] | [] | false | false | true | false | false | let append_distributes_le_seq_quad32_to_bytes s1 s2 =
| le_seq_quad32_to_bytes_reveal ();
calc ( == ) {
le_seq_quad32_to_bytes (s1 @| s2);
( == ) { () }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (s1 @| s2));
( == ) { append_distributes_seq_four_to_seq_LE s1 s2 }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s1 @| seq_four_to_seq_LE s2);
( == ) { append_distributes_seq_map (nat_to_four 8)
(seq_four_to_seq_LE s1)
(seq_four_to_seq_LE s2) }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s1) @|
seq_map (nat_to_four 8) (seq_four_to_seq_LE s2));
( == ) { append_distributes_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s1))
(seq_map (nat_to_four 8) (seq_four_to_seq_LE s2)) }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s1)) @|
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s2));
( == ) { () }
le_seq_quad32_to_bytes s1 @| le_seq_quad32_to_bytes s2;
} | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_nat8_dec_pad | val print_nat8_dec_pad: x:nat{x <= maxint U8} -> FStar.All.ML unit | val print_nat8_dec_pad: x:nat{x <= maxint U8} -> FStar.All.ML unit | let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x)) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 22,
"start_col": 0,
"start_line": 21
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Prims.nat{x <= Lib.IntTypes.maxint Lib.IntTypes.U8} -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.maxint",
"Lib.IntTypes.U8",
"FStar.IO.print_uint8_dec_pad",
"Lib.RawIntTypes.u8_to_UInt8",
"Lib.IntTypes.u8",
"Prims.unit"
] | [] | false | true | false | false | false | let print_nat8_dec_pad x =
| IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x)) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_nat8_dec | val print_nat8_dec: x:nat{x <= maxint U8} -> FStar.All.ML unit | val print_nat8_dec: x:nat{x <= maxint U8} -> FStar.All.ML unit | let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x)) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 19,
"start_col": 0,
"start_line": 18
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Prims.nat{x <= Lib.IntTypes.maxint Lib.IntTypes.U8} -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.maxint",
"Lib.IntTypes.U8",
"FStar.IO.print_uint8_dec",
"Lib.RawIntTypes.u8_to_UInt8",
"Lib.IntTypes.u8",
"Prims.unit"
] | [] | false | true | false | false | false | let print_nat8_dec x =
| IO.print_uint8_dec (u8_to_UInt8 (u8 x)) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_uint64_dec | val print_uint64_dec: uint64 -> FStar.All.ML unit | val print_uint64_dec: uint64 -> FStar.All.ML unit | let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 84,
"start_col": 0,
"start_line": 83
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Lib.IntTypes.uint64 -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.IO.print_uint64_dec",
"Lib.RawIntTypes.u64_to_UInt64",
"Prims.unit"
] | [] | false | true | false | false | false | let print_uint64_dec x =
| IO.print_uint64_dec (u64_to_UInt64 x) | false |
Vale.Arch.Types.fst | Vale.Arch.Types.append_distributes_le_bytes_to_seq_quad32 | val append_distributes_le_bytes_to_seq_quad32 (s1:seq nat8 { length s1 % 16 == 0 }) (s2:seq nat8 { length s2 % 16 == 0 }) :
Lemma(le_bytes_to_seq_quad32 (s1 @| s2) == (le_bytes_to_seq_quad32 s1) @| (le_bytes_to_seq_quad32 s2)) | val append_distributes_le_bytes_to_seq_quad32 (s1:seq nat8 { length s1 % 16 == 0 }) (s2:seq nat8 { length s2 % 16 == 0 }) :
Lemma(le_bytes_to_seq_quad32 (s1 @| s2) == (le_bytes_to_seq_quad32 s1) @| (le_bytes_to_seq_quad32 s2)) | let append_distributes_le_bytes_to_seq_quad32 (s1:seq nat8 { length s1 % 16 == 0 }) (s2:seq nat8 { length s2 % 16 == 0 }) :
Lemma(le_bytes_to_seq_quad32 (s1 @| s2) == (le_bytes_to_seq_quad32 s1) @| (le_bytes_to_seq_quad32 s2))
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
let s1' = seq_nat8_to_seq_nat32_LE s1 in
let s2' = seq_nat8_to_seq_nat32_LE s2 in
// (le_bytes_to_seq_quad32 s1) @| (le_bytes_to_seq_quad32 s2))
// = { Definition of le_bytes_to_seq_quad32 }
// seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s1) @| seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s2)
append_distributes_seq_to_seq_four_LE s1' s2';
// =
// seq_to_seq_four_LE ((seq_nat8_to_seq_nat32_LE s1) @| (seq_nat8_to_seq_nat32_LE s2))
append_distributes_seq_map (four_to_nat 8) (seq_to_seq_four_LE s1) (seq_to_seq_four_LE s2);
// seq_to_seq_four_LE (seq_map (four_to_nat 8) ((seq_to_seq_four_LE s1) @| (seq_to_seq_four_LE s2)))
append_distributes_seq_to_seq_four_LE s1 s2;
// seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (s1 @| s2)))
// le_bytes_to_seq_quad32 (s1 @| s2)
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 694,
"start_col": 0,
"start_line": 677
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal ()
let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
()
let lemma_equality_check_helper (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF)
)
=
// lemma_equality_check_helper_lo q;
// lemma_equality_check_helper_hi q;
lo64_reveal ();
hi64_reveal ();
assert (forall (x:two nat32).{:pattern (two_to_nat 32 x)} two_to_nat 32 x == two_to_nat_unfold 32 x);
()
let push_pop_xmm (x y:quad32) : Lemma
(let x' = insert_nat64 (insert_nat64 y (hi64 x) 1) (lo64 x) 0 in
x == x')
=
// assert (nat_to_two 32 (hi64 x) == two_select (four_to_two_two x) 1);
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_insrq_extrq_relations (x y:quad32) :
Lemma (let z = insert_nat64 x (lo64 y) 0 in
z == Mkfour y.lo0 y.lo1 x.hi2 x.hi3 /\
(let z = insert_nat64 x (hi64 y) 1 in
z == Mkfour x.lo0 x.lo1 y.hi2 y.hi3))
=
let open Vale.Def.Words.Two in
let z = insert_nat64 x (lo64 y) 0 in
insert_nat64_reveal ();
lo64_reveal ();
hi64_reveal ();
assert (z == insert_nat64_def x (lo64_def y) 0);
//assert (q'.hi2 == q.hi2);
//assert (q'.hi3 == q.hi3);
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (lo64 q)) 0));
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (nat_to_two 32 (two_to_nat 32 (two_select (four_to_two_two q) 0))) 0));
let Mktwo n1 n2 = two_select (four_to_two_two y) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two y) 1 in
nat_to_two_to_nat n1 n2;
//assert (q' == two_two_to_four (two_insert (four_to_two_two q) (two_select (four_to_two_two q) 0) 0));
//assert (q'.lo1 == q.lo1);
//assert (q == q');
()
open Vale.Def.Words.Two
let le_bytes_to_nat64_to_bytes s =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_nat64_to_bytes_to_nat64 n =
le_nat64_to_bytes_reveal ();
le_bytes_to_nat64_reveal ()
let le_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (le_bytes_to_seq_quad32 s)) } length s == 0 ==> length (le_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
()
let be_bytes_to_seq_quad32_empty () :
Lemma (forall s . {:pattern (length (be_bytes_to_seq_quad32 s)) } length s == 0 ==> length (be_bytes_to_seq_quad32 s) == 0)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
()
#reset-options "--z3rlimit 10 --max_fuel 0 --max_ifuel 0 --using_facts_from '* -FStar.Seq.Properties'"
let le_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
le_bytes_to_seq_quad32 (le_quad32_to_bytes b);
== {reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_quad32_to_bytes b));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))));
== {}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b)))));
== {seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE b))}
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_LE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_LE b)}
seq_to_seq_four_LE (four_to_seq_LE b);
== {four_to_seq_LE_is_seq_four_to_seq_LE b}
seq_to_seq_four_LE (seq_four_to_seq_LE (create 1 b));
== {}
create 1 b;
}
let be_bytes_to_seq_quad32_to_bytes_one_quad b =
calc (==) {
be_bytes_to_seq_quad32 (be_quad32_to_bytes b);
== {reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (be_quad32_to_bytes b));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_to_seq_four_BE (seq_nat8_to_seq_nat32_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))));
== {}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE (seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b)))));
== {seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE b))}
seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_map (nat_to_four 8) (four_to_seq_BE b)));
== {seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE b)}
seq_to_seq_four_BE (four_to_seq_BE b);
== {four_to_seq_BE_is_seq_four_to_seq_BE b}
seq_to_seq_four_BE (seq_four_to_seq_BE (create 1 b));
== {}
create 1 b;
}
let le_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes s) == s)
(* This expands into showing:
le_bytes_to_seq_quad32 (le_quad32_to_bytes s)
== { definition of le_bytes_to_seq_quad32 }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (le_seq_quad32_to_bytes s))
== { definition of le_seq_quad32_to_bytes }
seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s)))
== { definition of seq_nat8_to_seq_nat32_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE s))))
== { definition of seq_nat32_to_seq_nat8_LE }
seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)))))
*)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
seq_to_seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_LE s);
seq_to_seq_four_to_seq_LE (s) ;
()
let be_bytes_to_seq_quad32_to_bytes (s:seq quad32) :
Lemma (be_bytes_to_seq_quad32 (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == s)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_four_to_seq_BE s));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (seq_four_to_seq_BE s);
seq_to_seq_four_to_seq_BE (s) ;
()
let le_seq_quad32_to_bytes_to_seq_quad32 s =
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_seq_quad32_to_bytes_reveal ();
calc (==) {
le_seq_quad32_to_bytes (le_bytes_to_seq_quad32 s);
(==) { }
seq_nat32_to_seq_nat8_LE (seq_four_to_seq_LE (seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE s)));
(==) { }
s;
}
(*
le_quad32_to_bytes (le_bytes_to_quad32 s)
== { definition of le_quad32_to_bytes }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (le_bytes_to_quad32 s)))
== { definition of le_bytes_to_quad32 }
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))))
*)
let le_quad32_to_bytes_to_quad32 s =
calc (==) {
le_quad32_to_bytes (le_bytes_to_quad32 s);
== {le_bytes_to_quad32_reveal ()}
le_quad32_to_bytes (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (four_to_seq_LE (seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)))));
== {four_to_seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE s))}
seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_LE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_LE s)}
seq_four_to_seq_LE (seq_to_seq_four_LE s);
== {}
s;
}
let be_quad32_to_bytes_to_quad32 s =
calc (==) {
be_quad32_to_bytes (be_bytes_to_quad32 s);
== {be_bytes_to_quad32_reveal ()}
be_quad32_to_bytes (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE (seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)))));
== {four_to_seq_to_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE s))}
seq_four_to_seq_BE (seq_map (nat_to_four 8) (seq_map (four_to_nat 8) (seq_to_seq_four_BE s)));
== {seq_map_inverses (four_to_nat 8) (nat_to_four 8) (seq_to_seq_four_BE s)}
seq_four_to_seq_BE (seq_to_seq_four_BE s);
== {}
s;
}
let le_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q))
=
le_seq_quad32_to_bytes_reveal ();
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
four_to_seq_LE_is_seq_four_to_seq_LE q;
()
let be_seq_quad32_to_bytes_of_singleton (q:quad32) :
Lemma (be_quad32_to_bytes q == seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (create 1 q)))
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
four_to_seq_BE_is_seq_four_to_seq_BE q;
()
let le_quad32_to_bytes_injective ():
Lemma (forall b b' . le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%le_quad32_to_bytes) le_quad32_to_bytes;
let helper (b b':quad32) : Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b') =
if le_quad32_to_bytes b = le_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_LE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_LE b') in
assert (le_quad32_to_bytes b == seq_four_to_seq_LE b1);
assert (le_quad32_to_bytes b' == seq_four_to_seq_LE b1');
seq_four_to_seq_LE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_LE b) (four_to_seq_LE b');
assert ((four_to_seq_LE b) == (four_to_seq_LE b'));
four_to_seq_LE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let be_quad32_to_bytes_injective ():
Lemma (forall b b' . be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
reveal_opaque (`%be_quad32_to_bytes) be_quad32_to_bytes;
let helper (b b':quad32) : Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b') =
if be_quad32_to_bytes b = be_quad32_to_bytes b' then (
let b1 = seq_map (nat_to_four 8) (four_to_seq_BE b) in
let b1' = seq_map (nat_to_four 8) (four_to_seq_BE b') in
assert (be_quad32_to_bytes b == seq_four_to_seq_BE b1);
assert (be_quad32_to_bytes b' == seq_four_to_seq_BE b1');
seq_four_to_seq_BE_injective_specific b1 b1';
assert (b1 == b1');
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (four_to_seq_BE b) (four_to_seq_BE b');
assert ((four_to_seq_BE b) == (four_to_seq_BE b'));
four_to_seq_BE_injective nat32;
()
) else
()
in
FStar.Classical.forall_intro_2 helper
let le_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (le_quad32_to_bytes b == le_quad32_to_bytes b' ==> b == b')
=
le_quad32_to_bytes_injective()
let be_quad32_to_bytes_injective_specific (b b':quad32) :
Lemma (be_quad32_to_bytes b == be_quad32_to_bytes b' ==> b == b')
=
be_quad32_to_bytes_injective()
let le_seq_quad32_to_bytes_injective (b b':seq quad32) =
le_seq_quad32_to_bytes_reveal ();
seq_four_to_seq_LE_injective nat8;
nat_to_four_8_injective();
seq_map_injective (nat_to_four 8) (seq_four_to_seq_LE b) (seq_four_to_seq_LE b');
seq_four_to_seq_LE_injective_specific b b';
assert (equal b b')
let seq_to_four_LE_is_seq_to_seq_four_LE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_LE s) == seq_to_seq_four_LE s)
=
reveal_opaque (`%seq_to_seq_four_LE) (seq_to_seq_four_LE #a);
assert (equal (create 1 (seq_to_four_LE s)) (seq_to_seq_four_LE s));
()
let seq_to_four_BE_is_seq_to_seq_four_BE (#a:Type) (s:seq4 a) : Lemma
(create 1 (seq_to_four_BE s) == seq_to_seq_four_BE s)
=
reveal_opaque (`%seq_to_seq_four_BE) (seq_to_seq_four_BE #a);
assert (equal (create 1 (seq_to_four_BE s)) (seq_to_seq_four_BE s));
()
let le_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == le_bytes_to_quad32 b)
(ensures create 1 q == le_bytes_to_seq_quad32 b)
=
reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
le_bytes_to_quad32_reveal ();
seq_to_four_LE_is_seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b));
// q == le_bytes_to_quad32 b
// == seq_to_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
//
// == seq_to_seq_four_LE (seq_map (four_to_nat 8) (seq_to_seq_four_LE b))
// le_bytes_to_seq_quad32 b == seq_to_seq_four_LE (seq_nat8_to_seq_nat32_LE b)
()
let be_bytes_to_seq_quad_of_singleton (q:quad32) (b:seq nat8 { length b == 16 }) : Lemma
(requires q == be_bytes_to_quad32 b)
(ensures create 1 q == be_bytes_to_seq_quad32 b)
=
reveal_opaque (`%be_bytes_to_seq_quad32) be_bytes_to_seq_quad32;
be_bytes_to_quad32_reveal ();
seq_to_four_BE_is_seq_to_seq_four_BE (seq_map (four_to_nat 8) (seq_to_seq_four_BE b));
()
let le_bytes_to_quad32_to_bytes (q:quad32) :
Lemma(le_bytes_to_quad32 (le_quad32_to_bytes q) == q)
=
le_seq_quad32_to_bytes_of_singleton q; // ==> le_quad32_to_bytes q == le_seq_quad32_to_bytes (create 1 q)
let b = le_quad32_to_bytes q in
let q' = le_bytes_to_quad32 b in
le_bytes_to_seq_quad_of_singleton q' b; // ==> create 1 q' == le_bytes_to_seq_quad32 b
// == le_bytes_to_seq_quad32 (le_seq_quad32_to_bytes (create 1 q))
le_bytes_to_seq_quad32_to_bytes (create 1 q); // == create 1 q
//assert (create 1 q == create 1 q');
//assert (equal (create 1 q) (create 1 q'));
assert (q == index (create 1 q) 0); // OBSERVE
assert (q == q');
()
let be_bytes_to_quad32_to_bytes (q:quad32) :
Lemma (be_bytes_to_quad32 (be_quad32_to_bytes q) == q)
=
be_bytes_to_quad32_reveal ();
let q':quad32 = be_bytes_to_quad32 (be_quad32_to_bytes q) in
seq_to_seq_four_to_seq_BE (seq_map (nat_to_four 8) (four_to_seq_BE q));
seq_map_inverses (nat_to_four 8) (four_to_nat 8) (four_to_seq_BE q);
seq_to_four_to_seq_BE q;
()
let lemma_reverse_reverse_bytes_nat32_quad32 (s:quad32) :
Lemma (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s) == s)
[SMTPat (reverse_bytes_nat32_quad32 (reverse_bytes_nat32_quad32 s))]
=
let s' = reverse_bytes_nat32_quad32 s in
let s''= reverse_bytes_nat32_quad32 s' in
assert (s''.lo0 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo0)); // OBSERVE
assert (s''.lo1 == reverse_bytes_nat32 (reverse_bytes_nat32 s.lo1)); // OBSERVE
assert (s''.hi2 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi2)); // OBSERVE
assert (s''.hi3 == reverse_bytes_nat32 (reverse_bytes_nat32 s.hi3)); // OBSERVE
()
let lemma_reverse_reverse_bytes_nat32_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s) == s)
[SMTPat (reverse_bytes_nat32_quad32_seq (reverse_bytes_nat32_quad32_seq s))]
=
seq_map_inverses reverse_bytes_nat32_quad32 reverse_bytes_nat32_quad32 s
let lemma_reverse_reverse_bytes_quad32_seq (s:seq quad32) :
Lemma (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s) == s)
[SMTPat (reverse_bytes_quad32_seq (reverse_bytes_quad32_seq s))]
=
seq_map_inverses reverse_bytes_quad32 reverse_bytes_quad32 s
let lemma_le_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (le_seq_quad32_to_bytes s) == (length s) * 16)
=
()
let lemma_be_seq_quad32_to_bytes_length (s:seq quad32) :
Lemma(length (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) == (length s) * 16)
=
()
let slice_commutes_seq_four_to_seq_LE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) ==
seq_four_to_seq_LE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_LE) (seq_four_to_seq_LE #a);
assert (equal (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
(seq_four_to_seq_LE (slice s n n')));
()
let slice_commutes_seq_four_to_seq_BE (#a:Type) (s:seq (four a)) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) ==
seq_four_to_seq_BE (slice s n n'))
=
reveal_opaque (`%seq_four_to_seq_BE) (seq_four_to_seq_BE #a);
assert (equal (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4))
(seq_four_to_seq_BE (slice s n n')));
()
let slice_commutes_le_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16) ==
le_seq_quad32_to_bytes (slice s n n'))
=
le_seq_quad32_to_bytes_reveal ();
slice_commutes_seq_four_to_seq_LE s n n';
assert (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4) == seq_four_to_seq_LE (slice s n n'));
(*
le_seq_quad32_to_bytes (slice s n n') == seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE (slice s n n')));
== seq_four_to_seq_LE (seq_map (nat_to_four 8) (slice (seq_four_to_seq_LE s) (n * 4) (n' * 4))
slice (le_seq_quad32_to_bytes s) (n * 16) (n' * 16)
== slice (seq_four_to_seq_LE (seq_map (nat_to_four 8) (seq_four_to_seq_LE s))) (n * 16) (n' * 16)
== seq_four_to_seq_LE (slice (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) (n * 4) (n' * 4))
*)
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_LE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_LE s)) in
slice_commutes_seq_four_to_seq_LE s_inner (n * 4) (n' * 4);
()
let slice_commutes_be_seq_quad32_to_bytes (s:seq quad32) (n:nat{n <= length s}) (n':nat{ n <= n' /\ n' <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) (n * 16) (n' * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s n n')))
=
slice_commutes_seq_four_to_seq_BE s n n';
assert (slice (seq_four_to_seq_BE s) (n * 4) (n' * 4) == seq_four_to_seq_BE (slice s n n'));
slice_seq_map_commute (nat_to_four 8) (seq_four_to_seq_BE s) (n*4) (n'*4);
let s_inner = (seq_map (nat_to_four 8) (seq_four_to_seq_BE s)) in
slice_commutes_seq_four_to_seq_BE s_inner (n * 4) (n' * 4);
()
let slice_commutes_le_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (le_seq_quad32_to_bytes s) 0 (n * 16) ==
le_seq_quad32_to_bytes (slice s 0 n))
=
slice_commutes_le_seq_quad32_to_bytes s 0 n
let slice_commutes_be_seq_quad32_to_bytes0 (s:seq quad32) (n:nat{n <= length s}) :
Lemma(slice (seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE s)) 0 (n * 16) ==
seq_nat32_to_seq_nat8_BE (seq_four_to_seq_BE (slice s 0 n)))
=
slice_commutes_be_seq_quad32_to_bytes s 0 n | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 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": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
s1: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length s1 % 16 == 0} ->
s2: FStar.Seq.Base.seq Vale.Def.Words_s.nat8 {FStar.Seq.Base.length s2 % 16 == 0}
-> FStar.Pervasives.Lemma
(ensures
Vale.Def.Types_s.le_bytes_to_seq_quad32 (s1 @| s2) ==
Vale.Def.Types_s.le_bytes_to_seq_quad32 s1 @| Vale.Def.Types_s.le_bytes_to_seq_quad32 s2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat8",
"Prims.eq2",
"Prims.int",
"Prims.op_Modulus",
"FStar.Seq.Base.length",
"Prims.unit",
"Vale.Def.Words.Seq.append_distributes_seq_to_seq_four_LE",
"Vale.Lib.Seqs.append_distributes_seq_map",
"Vale.Def.Words_s.four",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"FStar.Mul.op_Star",
"Vale.Def.Words.Four_s.four_to_nat",
"Vale.Def.Words.Seq_s.seq_to_seq_four_LE",
"Vale.Def.Words_s.nat32",
"Vale.Def.Words.Seq_s.seq_nat8_to_seq_nat32_LE",
"FStar.Pervasives.reveal_opaque",
"Vale.Def.Types_s.nat8",
"Vale.Def.Types_s.quad32",
"Prims.l_True",
"Vale.Def.Types_s.le_bytes_to_seq_quad32",
"Prims.squash",
"FStar.Seq.Base.op_At_Bar",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let append_distributes_le_bytes_to_seq_quad32
(s1: seq nat8 {length s1 % 16 == 0})
(s2: seq nat8 {length s2 % 16 == 0})
: Lemma
(le_bytes_to_seq_quad32 (s1 @| s2) == (le_bytes_to_seq_quad32 s1) @| (le_bytes_to_seq_quad32 s2)
) =
| reveal_opaque (`%le_bytes_to_seq_quad32) le_bytes_to_seq_quad32;
let s1' = seq_nat8_to_seq_nat32_LE s1 in
let s2' = seq_nat8_to_seq_nat32_LE s2 in
append_distributes_seq_to_seq_four_LE s1' s2';
append_distributes_seq_map (four_to_nat 8) (seq_to_seq_four_LE s1) (seq_to_seq_four_LE s2);
append_distributes_seq_to_seq_four_LE s1 s2;
() | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_nat32_hex_pad | val print_nat32_hex_pad: x:nat{x <= maxint U32} -> FStar.All.ML unit | val print_nat32_hex_pad: x:nat{x <= maxint U32} -> FStar.All.ML unit | let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x)) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 29,
"start_col": 0,
"start_line": 28
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Prims.nat{x <= Lib.IntTypes.maxint Lib.IntTypes.U32} -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.maxint",
"Lib.IntTypes.U32",
"FStar.IO.print_uint32_hex_pad",
"Lib.RawIntTypes.u32_to_UInt32",
"Lib.IntTypes.u32",
"Prims.unit"
] | [] | false | true | false | false | false | let print_nat32_hex_pad x =
| IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x)) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_label_lbytes | val print_label_lbytes: display:bool -> string -> len:size_nat -> lbytes len -> FStar.All.ML unit | val print_label_lbytes: display:bool -> string -> len:size_nat -> lbytes len -> FStar.All.ML unit | let print_label_lbytes flag label len b =
if not flag then () else (
IO.print_string label;
IO.print_string ": \n";
print_lbytes flag len b;
IO.print_newline ()) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 151,
"start_col": 0,
"start_line": 146
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x)
let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x)
let print_label_nat64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n")
let print_label_uint8 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint8_hex_pad x;
IO.print_string "\n")
let print_label_uint32 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint32_hex_pad x;
IO.print_string "\n")
let print_label_uint64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint64_hex_pad x;
IO.print_string "\n")
let print_list_nat64 flag l =
if not flag then ()
else (
repeat_range_all_ml 0 (List.Tot.length l) (fun i _ ->
print_nat64_dec (List.Tot.index l i);
IO.print_string " "
) ())
let print_string flag s = if flag then IO.print_string s else ()
let print_lbytes flag len b =
if not flag then () else (
let q = 32 in
let n = len / q in
let r = len % q in
if n = 0 then (
List.iter (fun a -> print_uint8_hex_pad a) (to_list b))
else (
repeat_range_all_ml 0 n (fun i _ ->
let sb = sub #uint8 #len b (i * q) q in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb);
(if i < n - 1 then IO.print_string "\n" else ())) ();
(if r <> 0 then IO.print_newline ());
let sb = sub #uint8 #len b (n * q) r in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 |
display: Prims.bool ->
label: Prims.string ->
len: Lib.IntTypes.size_nat ->
b: Lib.ByteSequence.lbytes len
-> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Prims.string",
"Lib.IntTypes.size_nat",
"Lib.ByteSequence.lbytes",
"Prims.op_Negation",
"Prims.unit",
"FStar.IO.print_newline",
"Lib.PrintSequence.print_lbytes",
"FStar.IO.print_string"
] | [] | false | true | false | false | false | let print_label_lbytes flag label len b =
| if not flag
then ()
else
(IO.print_string label;
IO.print_string ": \n";
print_lbytes flag len b;
IO.print_newline ()) | false |
Vale.X64.CPU_Features_s.fst | Vale.X64.CPU_Features_s.avx512_xcr0 | val avx512_xcr0:bool | val avx512_xcr0:bool | let avx512_xcr0 : bool =
avx_xcr0_enabled && opmask_xcr0_enabled && zmm_hi256_xcr0_enabled && hi16_zmm_xcr0_enabled | {
"file_name": "vale/specs/hardware/Vale.X64.CPU_Features_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 92,
"end_line": 76,
"start_col": 0,
"start_line": 75
} | module Vale.X64.CPU_Features_s
open FStar.Mul
open Vale.X64.Machine_s
open Vale.Def.Words_s
(* CPUID *)
assume val aesni_enabled : bool // CPUID.01H:ECX.AESNI[bit 25]
assume val avx_cpuid_enabled : bool // CPUID.01H:ECX.AVX[bit 28]
assume val pclmulqdq_enabled : bool // CPUID.01H:ECX.PCLMULQDQ[bit 1]
assume val avx2_cpuid_enabled : bool // CPUID.7.0.EBX[5]
assume val bmi2_enabled : bool // CPUID.7.0.EBX[8]
assume val avx512f_enabled : bool // CPUID.7.0.EBX[16]
assume val avx512dq_enabled : bool // CPUID.7.0.EBX[17]
assume val adx_enabled : bool // CPUID.7.0.EBX[19]
assume val sha_enabled : bool // CPUID.7.0.EBX[29]
assume val avx512bw_enabled : bool // CPUID.7.0.EBX[30]
assume val avx512vl_enabled : bool // CPUID.7.0.EBX[31]
assume val sse2_enabled : bool // CPUID.01H:EDX.SSE2[bit 26]
assume val ssse3_enabled : bool // CPUID.01H:ECX.SSSE3[bit 9]
assume val sse4_1_enabled : bool // CPUID.01H:ECX.SSE4.1[bit 19]
assume val movbe_enabled : bool // CPUID.01H.ECX.MOVBE[bit 22]
assume val osxsave_enabled : bool // CPUID.01H.ECX.OSXSAVE[bit 27]
assume val rdrand_enabled : bool // CPUID.01H.ECX.RDRAND[bit 30] = 0
let sse_enabled : bool = sse2_enabled && ssse3_enabled && sse4_1_enabled
let avx512_cpuid_enabled : bool =
avx512f_enabled && avx512dq_enabled && avx512bw_enabled && avx512vl_enabled
assume val cpuid (r:reg_64) (rax:nat64) (rcx:nat64) : nat64
assume val cpuid_features (u:unit) :
Lemma ((forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 25) > 0) = aesni_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 28) > 0) = avx_cpuid_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 1) > 0) = pclmulqdq_enabled) /\
(forall rcx . {:pattern (cpuid rRdx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRdx 1 rcx) (pow2_norm 26) > 0) = sse2_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 9) > 0) = ssse3_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 19) > 0) = sse4_1_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 22) > 0) = movbe_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 27) > 0) = osxsave_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 30) > 0) = rdrand_enabled) /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 5) > 0) = avx2_cpuid_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 8) > 0) = bmi2_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 16) > 0) = avx512f_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 17) > 0) = avx512dq_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 19) > 0) = adx_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 29) > 0) = sha_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 30) > 0) = avx512bw_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 31) > 0) = avx512vl_enabled
)
(* Extended Control Registers *)
assume val sse_xcr0_enabled : bool // Bit 1
assume val avx_xcr0_enabled : bool // Bit 2
assume val opmask_xcr0_enabled : bool // Bit 5
assume val zmm_hi256_xcr0_enabled : bool // Bit 6
assume val hi16_zmm_xcr0_enabled : bool // Bit 7
assume val xgetbv (r:reg_64) (rcx:nat64) : nat64
assume val xgetbv_features (u:unit) :
Lemma ((Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 1) > 0) = sse_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 2) > 0) = avx_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 5) > 0) = opmask_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 6) > 0) = zmm_hi256_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 7) > 0) = hi16_zmm_xcr0_enabled
)
let avx_xcr0 : bool = sse_xcr0_enabled && avx_xcr0_enabled | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.CPU_Features_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.op_AmpAmp",
"Vale.X64.CPU_Features_s.avx_xcr0_enabled",
"Vale.X64.CPU_Features_s.opmask_xcr0_enabled",
"Vale.X64.CPU_Features_s.zmm_hi256_xcr0_enabled",
"Vale.X64.CPU_Features_s.hi16_zmm_xcr0_enabled"
] | [] | false | false | false | true | false | let avx512_xcr0:bool =
| avx_xcr0_enabled && opmask_xcr0_enabled && zmm_hi256_xcr0_enabled && hi16_zmm_xcr0_enabled | false |
Vale.X64.CPU_Features_s.fst | Vale.X64.CPU_Features_s.sse_enabled | val sse_enabled:bool | val sse_enabled:bool | let sse_enabled : bool = sse2_enabled && ssse3_enabled && sse4_1_enabled | {
"file_name": "vale/specs/hardware/Vale.X64.CPU_Features_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 72,
"end_line": 28,
"start_col": 0,
"start_line": 28
} | module Vale.X64.CPU_Features_s
open FStar.Mul
open Vale.X64.Machine_s
open Vale.Def.Words_s
(* CPUID *)
assume val aesni_enabled : bool // CPUID.01H:ECX.AESNI[bit 25]
assume val avx_cpuid_enabled : bool // CPUID.01H:ECX.AVX[bit 28]
assume val pclmulqdq_enabled : bool // CPUID.01H:ECX.PCLMULQDQ[bit 1]
assume val avx2_cpuid_enabled : bool // CPUID.7.0.EBX[5]
assume val bmi2_enabled : bool // CPUID.7.0.EBX[8]
assume val avx512f_enabled : bool // CPUID.7.0.EBX[16]
assume val avx512dq_enabled : bool // CPUID.7.0.EBX[17]
assume val adx_enabled : bool // CPUID.7.0.EBX[19]
assume val sha_enabled : bool // CPUID.7.0.EBX[29]
assume val avx512bw_enabled : bool // CPUID.7.0.EBX[30]
assume val avx512vl_enabled : bool // CPUID.7.0.EBX[31]
assume val sse2_enabled : bool // CPUID.01H:EDX.SSE2[bit 26]
assume val ssse3_enabled : bool // CPUID.01H:ECX.SSSE3[bit 9]
assume val sse4_1_enabled : bool // CPUID.01H:ECX.SSE4.1[bit 19]
assume val movbe_enabled : bool // CPUID.01H.ECX.MOVBE[bit 22]
assume val osxsave_enabled : bool // CPUID.01H.ECX.OSXSAVE[bit 27]
assume val rdrand_enabled : bool // CPUID.01H.ECX.RDRAND[bit 30] = 0 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.CPU_Features_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.op_AmpAmp",
"Vale.X64.CPU_Features_s.sse2_enabled",
"Vale.X64.CPU_Features_s.ssse3_enabled",
"Vale.X64.CPU_Features_s.sse4_1_enabled"
] | [] | false | false | false | true | false | let sse_enabled:bool =
| sse2_enabled && ssse3_enabled && sse4_1_enabled | false |
Vale.X64.CPU_Features_s.fst | Vale.X64.CPU_Features_s.avx512_cpuid_enabled | val avx512_cpuid_enabled:bool | val avx512_cpuid_enabled:bool | let avx512_cpuid_enabled : bool =
avx512f_enabled && avx512dq_enabled && avx512bw_enabled && avx512vl_enabled | {
"file_name": "vale/specs/hardware/Vale.X64.CPU_Features_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 31,
"start_col": 0,
"start_line": 30
} | module Vale.X64.CPU_Features_s
open FStar.Mul
open Vale.X64.Machine_s
open Vale.Def.Words_s
(* CPUID *)
assume val aesni_enabled : bool // CPUID.01H:ECX.AESNI[bit 25]
assume val avx_cpuid_enabled : bool // CPUID.01H:ECX.AVX[bit 28]
assume val pclmulqdq_enabled : bool // CPUID.01H:ECX.PCLMULQDQ[bit 1]
assume val avx2_cpuid_enabled : bool // CPUID.7.0.EBX[5]
assume val bmi2_enabled : bool // CPUID.7.0.EBX[8]
assume val avx512f_enabled : bool // CPUID.7.0.EBX[16]
assume val avx512dq_enabled : bool // CPUID.7.0.EBX[17]
assume val adx_enabled : bool // CPUID.7.0.EBX[19]
assume val sha_enabled : bool // CPUID.7.0.EBX[29]
assume val avx512bw_enabled : bool // CPUID.7.0.EBX[30]
assume val avx512vl_enabled : bool // CPUID.7.0.EBX[31]
assume val sse2_enabled : bool // CPUID.01H:EDX.SSE2[bit 26]
assume val ssse3_enabled : bool // CPUID.01H:ECX.SSSE3[bit 9]
assume val sse4_1_enabled : bool // CPUID.01H:ECX.SSE4.1[bit 19]
assume val movbe_enabled : bool // CPUID.01H.ECX.MOVBE[bit 22]
assume val osxsave_enabled : bool // CPUID.01H.ECX.OSXSAVE[bit 27]
assume val rdrand_enabled : bool // CPUID.01H.ECX.RDRAND[bit 30] = 0
let sse_enabled : bool = sse2_enabled && ssse3_enabled && sse4_1_enabled | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.CPU_Features_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.op_AmpAmp",
"Vale.X64.CPU_Features_s.avx512f_enabled",
"Vale.X64.CPU_Features_s.avx512dq_enabled",
"Vale.X64.CPU_Features_s.avx512bw_enabled",
"Vale.X64.CPU_Features_s.avx512vl_enabled"
] | [] | false | false | false | true | false | let avx512_cpuid_enabled:bool =
| avx512f_enabled && avx512dq_enabled && avx512bw_enabled && avx512vl_enabled | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_nat32_dec | val print_nat32_dec: x:nat{x <= maxint U32} -> FStar.All.ML unit | val print_nat32_dec: x:nat{x <= maxint U32} -> FStar.All.ML unit | let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x)) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 32,
"start_col": 0,
"start_line": 31
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Prims.nat{x <= Lib.IntTypes.maxint Lib.IntTypes.U32} -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.maxint",
"Lib.IntTypes.U32",
"FStar.IO.print_uint32_dec",
"Lib.RawIntTypes.u32_to_UInt32",
"Lib.IntTypes.u32",
"Prims.unit"
] | [] | false | true | false | false | false | let print_nat32_dec x =
| IO.print_uint32_dec (u32_to_UInt32 (u32 x)) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_nat64_dec | val print_nat64_dec: x:nat{x <= maxint U64} -> FStar.All.ML unit | val print_nat64_dec: x:nat{x <= maxint U64} -> FStar.All.ML unit | let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x)) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 45,
"start_col": 0,
"start_line": 44
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Prims.nat{x <= Lib.IntTypes.maxint Lib.IntTypes.U64} -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.maxint",
"Lib.IntTypes.U64",
"FStar.IO.print_uint64_dec",
"Lib.RawIntTypes.u64_to_UInt64",
"Lib.IntTypes.u64",
"Prims.unit"
] | [] | false | true | false | false | false | let print_nat64_dec x =
| IO.print_uint64_dec (u64_to_UInt64 (u64 x)) | false |
Vale.X64.CPU_Features_s.fst | Vale.X64.CPU_Features_s.avx512_enabled | val avx512_enabled:bool | val avx512_enabled:bool | let avx512_enabled : bool = avx512_cpuid_enabled && avx512_xcr0 | {
"file_name": "vale/specs/hardware/Vale.X64.CPU_Features_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 83,
"start_col": 0,
"start_line": 83
} | module Vale.X64.CPU_Features_s
open FStar.Mul
open Vale.X64.Machine_s
open Vale.Def.Words_s
(* CPUID *)
assume val aesni_enabled : bool // CPUID.01H:ECX.AESNI[bit 25]
assume val avx_cpuid_enabled : bool // CPUID.01H:ECX.AVX[bit 28]
assume val pclmulqdq_enabled : bool // CPUID.01H:ECX.PCLMULQDQ[bit 1]
assume val avx2_cpuid_enabled : bool // CPUID.7.0.EBX[5]
assume val bmi2_enabled : bool // CPUID.7.0.EBX[8]
assume val avx512f_enabled : bool // CPUID.7.0.EBX[16]
assume val avx512dq_enabled : bool // CPUID.7.0.EBX[17]
assume val adx_enabled : bool // CPUID.7.0.EBX[19]
assume val sha_enabled : bool // CPUID.7.0.EBX[29]
assume val avx512bw_enabled : bool // CPUID.7.0.EBX[30]
assume val avx512vl_enabled : bool // CPUID.7.0.EBX[31]
assume val sse2_enabled : bool // CPUID.01H:EDX.SSE2[bit 26]
assume val ssse3_enabled : bool // CPUID.01H:ECX.SSSE3[bit 9]
assume val sse4_1_enabled : bool // CPUID.01H:ECX.SSE4.1[bit 19]
assume val movbe_enabled : bool // CPUID.01H.ECX.MOVBE[bit 22]
assume val osxsave_enabled : bool // CPUID.01H.ECX.OSXSAVE[bit 27]
assume val rdrand_enabled : bool // CPUID.01H.ECX.RDRAND[bit 30] = 0
let sse_enabled : bool = sse2_enabled && ssse3_enabled && sse4_1_enabled
let avx512_cpuid_enabled : bool =
avx512f_enabled && avx512dq_enabled && avx512bw_enabled && avx512vl_enabled
assume val cpuid (r:reg_64) (rax:nat64) (rcx:nat64) : nat64
assume val cpuid_features (u:unit) :
Lemma ((forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 25) > 0) = aesni_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 28) > 0) = avx_cpuid_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 1) > 0) = pclmulqdq_enabled) /\
(forall rcx . {:pattern (cpuid rRdx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRdx 1 rcx) (pow2_norm 26) > 0) = sse2_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 9) > 0) = ssse3_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 19) > 0) = sse4_1_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 22) > 0) = movbe_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 27) > 0) = osxsave_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 30) > 0) = rdrand_enabled) /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 5) > 0) = avx2_cpuid_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 8) > 0) = bmi2_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 16) > 0) = avx512f_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 17) > 0) = avx512dq_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 19) > 0) = adx_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 29) > 0) = sha_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 30) > 0) = avx512bw_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 31) > 0) = avx512vl_enabled
)
(* Extended Control Registers *)
assume val sse_xcr0_enabled : bool // Bit 1
assume val avx_xcr0_enabled : bool // Bit 2
assume val opmask_xcr0_enabled : bool // Bit 5
assume val zmm_hi256_xcr0_enabled : bool // Bit 6
assume val hi16_zmm_xcr0_enabled : bool // Bit 7
assume val xgetbv (r:reg_64) (rcx:nat64) : nat64
assume val xgetbv_features (u:unit) :
Lemma ((Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 1) > 0) = sse_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 2) > 0) = avx_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 5) > 0) = opmask_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 6) > 0) = zmm_hi256_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 7) > 0) = hi16_zmm_xcr0_enabled
)
let avx_xcr0 : bool = sse_xcr0_enabled && avx_xcr0_enabled
let avx512_xcr0 : bool =
avx_xcr0_enabled && opmask_xcr0_enabled && zmm_hi256_xcr0_enabled && hi16_zmm_xcr0_enabled
(* Full AVX detection *)
let avx_enabled : bool = avx_cpuid_enabled && avx_xcr0 | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.CPU_Features_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.op_AmpAmp",
"Vale.X64.CPU_Features_s.avx512_cpuid_enabled",
"Vale.X64.CPU_Features_s.avx512_xcr0"
] | [] | false | false | false | true | false | let avx512_enabled:bool =
| avx512_cpuid_enabled && avx512_xcr0 | false |
Vale.X64.CPU_Features_s.fst | Vale.X64.CPU_Features_s.avx2_enabled | val avx2_enabled:bool | val avx2_enabled:bool | let avx2_enabled : bool = avx2_cpuid_enabled && avx_xcr0 | {
"file_name": "vale/specs/hardware/Vale.X64.CPU_Features_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 56,
"end_line": 82,
"start_col": 0,
"start_line": 82
} | module Vale.X64.CPU_Features_s
open FStar.Mul
open Vale.X64.Machine_s
open Vale.Def.Words_s
(* CPUID *)
assume val aesni_enabled : bool // CPUID.01H:ECX.AESNI[bit 25]
assume val avx_cpuid_enabled : bool // CPUID.01H:ECX.AVX[bit 28]
assume val pclmulqdq_enabled : bool // CPUID.01H:ECX.PCLMULQDQ[bit 1]
assume val avx2_cpuid_enabled : bool // CPUID.7.0.EBX[5]
assume val bmi2_enabled : bool // CPUID.7.0.EBX[8]
assume val avx512f_enabled : bool // CPUID.7.0.EBX[16]
assume val avx512dq_enabled : bool // CPUID.7.0.EBX[17]
assume val adx_enabled : bool // CPUID.7.0.EBX[19]
assume val sha_enabled : bool // CPUID.7.0.EBX[29]
assume val avx512bw_enabled : bool // CPUID.7.0.EBX[30]
assume val avx512vl_enabled : bool // CPUID.7.0.EBX[31]
assume val sse2_enabled : bool // CPUID.01H:EDX.SSE2[bit 26]
assume val ssse3_enabled : bool // CPUID.01H:ECX.SSSE3[bit 9]
assume val sse4_1_enabled : bool // CPUID.01H:ECX.SSE4.1[bit 19]
assume val movbe_enabled : bool // CPUID.01H.ECX.MOVBE[bit 22]
assume val osxsave_enabled : bool // CPUID.01H.ECX.OSXSAVE[bit 27]
assume val rdrand_enabled : bool // CPUID.01H.ECX.RDRAND[bit 30] = 0
let sse_enabled : bool = sse2_enabled && ssse3_enabled && sse4_1_enabled
let avx512_cpuid_enabled : bool =
avx512f_enabled && avx512dq_enabled && avx512bw_enabled && avx512vl_enabled
assume val cpuid (r:reg_64) (rax:nat64) (rcx:nat64) : nat64
assume val cpuid_features (u:unit) :
Lemma ((forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 25) > 0) = aesni_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 28) > 0) = avx_cpuid_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 1) > 0) = pclmulqdq_enabled) /\
(forall rcx . {:pattern (cpuid rRdx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRdx 1 rcx) (pow2_norm 26) > 0) = sse2_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 9) > 0) = ssse3_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 19) > 0) = sse4_1_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 22) > 0) = movbe_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 27) > 0) = osxsave_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 30) > 0) = rdrand_enabled) /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 5) > 0) = avx2_cpuid_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 8) > 0) = bmi2_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 16) > 0) = avx512f_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 17) > 0) = avx512dq_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 19) > 0) = adx_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 29) > 0) = sha_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 30) > 0) = avx512bw_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 31) > 0) = avx512vl_enabled
)
(* Extended Control Registers *)
assume val sse_xcr0_enabled : bool // Bit 1
assume val avx_xcr0_enabled : bool // Bit 2
assume val opmask_xcr0_enabled : bool // Bit 5
assume val zmm_hi256_xcr0_enabled : bool // Bit 6
assume val hi16_zmm_xcr0_enabled : bool // Bit 7
assume val xgetbv (r:reg_64) (rcx:nat64) : nat64
assume val xgetbv_features (u:unit) :
Lemma ((Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 1) > 0) = sse_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 2) > 0) = avx_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 5) > 0) = opmask_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 6) > 0) = zmm_hi256_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 7) > 0) = hi16_zmm_xcr0_enabled
)
let avx_xcr0 : bool = sse_xcr0_enabled && avx_xcr0_enabled
let avx512_xcr0 : bool =
avx_xcr0_enabled && opmask_xcr0_enabled && zmm_hi256_xcr0_enabled && hi16_zmm_xcr0_enabled
(* Full AVX detection *) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.CPU_Features_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.op_AmpAmp",
"Vale.X64.CPU_Features_s.avx2_cpuid_enabled",
"Vale.X64.CPU_Features_s.avx_xcr0"
] | [] | false | false | false | true | false | let avx2_enabled:bool =
| avx2_cpuid_enabled && avx_xcr0 | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_nat32_hex | val print_nat32_hex: x:nat{x <= maxint U32} -> FStar.All.ML unit | val print_nat32_hex: x:nat{x <= maxint U32} -> FStar.All.ML unit | let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x)) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 26,
"start_col": 0,
"start_line": 25
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Prims.nat{x <= Lib.IntTypes.maxint Lib.IntTypes.U32} -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.maxint",
"Lib.IntTypes.U32",
"FStar.IO.print_uint32",
"Lib.RawIntTypes.u32_to_UInt32",
"Lib.IntTypes.u32",
"Prims.unit"
] | [] | false | true | false | false | false | let print_nat32_hex x =
| IO.print_uint32 (u32_to_UInt32 (u32 x)) | false |
Vale.X64.CPU_Features_s.fst | Vale.X64.CPU_Features_s.avx_xcr0 | val avx_xcr0:bool | val avx_xcr0:bool | let avx_xcr0 : bool = sse_xcr0_enabled && avx_xcr0_enabled | {
"file_name": "vale/specs/hardware/Vale.X64.CPU_Features_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 73,
"start_col": 0,
"start_line": 73
} | module Vale.X64.CPU_Features_s
open FStar.Mul
open Vale.X64.Machine_s
open Vale.Def.Words_s
(* CPUID *)
assume val aesni_enabled : bool // CPUID.01H:ECX.AESNI[bit 25]
assume val avx_cpuid_enabled : bool // CPUID.01H:ECX.AVX[bit 28]
assume val pclmulqdq_enabled : bool // CPUID.01H:ECX.PCLMULQDQ[bit 1]
assume val avx2_cpuid_enabled : bool // CPUID.7.0.EBX[5]
assume val bmi2_enabled : bool // CPUID.7.0.EBX[8]
assume val avx512f_enabled : bool // CPUID.7.0.EBX[16]
assume val avx512dq_enabled : bool // CPUID.7.0.EBX[17]
assume val adx_enabled : bool // CPUID.7.0.EBX[19]
assume val sha_enabled : bool // CPUID.7.0.EBX[29]
assume val avx512bw_enabled : bool // CPUID.7.0.EBX[30]
assume val avx512vl_enabled : bool // CPUID.7.0.EBX[31]
assume val sse2_enabled : bool // CPUID.01H:EDX.SSE2[bit 26]
assume val ssse3_enabled : bool // CPUID.01H:ECX.SSSE3[bit 9]
assume val sse4_1_enabled : bool // CPUID.01H:ECX.SSE4.1[bit 19]
assume val movbe_enabled : bool // CPUID.01H.ECX.MOVBE[bit 22]
assume val osxsave_enabled : bool // CPUID.01H.ECX.OSXSAVE[bit 27]
assume val rdrand_enabled : bool // CPUID.01H.ECX.RDRAND[bit 30] = 0
let sse_enabled : bool = sse2_enabled && ssse3_enabled && sse4_1_enabled
let avx512_cpuid_enabled : bool =
avx512f_enabled && avx512dq_enabled && avx512bw_enabled && avx512vl_enabled
assume val cpuid (r:reg_64) (rax:nat64) (rcx:nat64) : nat64
assume val cpuid_features (u:unit) :
Lemma ((forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 25) > 0) = aesni_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 28) > 0) = avx_cpuid_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 1) > 0) = pclmulqdq_enabled) /\
(forall rcx . {:pattern (cpuid rRdx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRdx 1 rcx) (pow2_norm 26) > 0) = sse2_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 9) > 0) = ssse3_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 19) > 0) = sse4_1_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 22) > 0) = movbe_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 27) > 0) = osxsave_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 30) > 0) = rdrand_enabled) /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 5) > 0) = avx2_cpuid_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 8) > 0) = bmi2_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 16) > 0) = avx512f_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 17) > 0) = avx512dq_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 19) > 0) = adx_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 29) > 0) = sha_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 30) > 0) = avx512bw_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 31) > 0) = avx512vl_enabled
)
(* Extended Control Registers *)
assume val sse_xcr0_enabled : bool // Bit 1
assume val avx_xcr0_enabled : bool // Bit 2
assume val opmask_xcr0_enabled : bool // Bit 5
assume val zmm_hi256_xcr0_enabled : bool // Bit 6
assume val hi16_zmm_xcr0_enabled : bool // Bit 7
assume val xgetbv (r:reg_64) (rcx:nat64) : nat64
assume val xgetbv_features (u:unit) :
Lemma ((Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 1) > 0) = sse_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 2) > 0) = avx_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 5) > 0) = opmask_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 6) > 0) = zmm_hi256_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 7) > 0) = hi16_zmm_xcr0_enabled
) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.CPU_Features_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.op_AmpAmp",
"Vale.X64.CPU_Features_s.sse_xcr0_enabled",
"Vale.X64.CPU_Features_s.avx_xcr0_enabled"
] | [] | false | false | false | true | false | let avx_xcr0:bool =
| sse_xcr0_enabled && avx_xcr0_enabled | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_nat32_dec_pad | val print_nat32_dec_pad: x:nat{x <= maxint U32} -> FStar.All.ML unit | val print_nat32_dec_pad: x:nat{x <= maxint U32} -> FStar.All.ML unit | let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x)) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 35,
"start_col": 0,
"start_line": 34
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Prims.nat{x <= Lib.IntTypes.maxint Lib.IntTypes.U32} -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.maxint",
"Lib.IntTypes.U32",
"FStar.IO.print_uint32_dec_pad",
"Lib.RawIntTypes.u32_to_UInt32",
"Lib.IntTypes.u32",
"Prims.unit"
] | [] | false | true | false | false | false | let print_nat32_dec_pad x =
| IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x)) | false |
Vale.X64.CPU_Features_s.fst | Vale.X64.CPU_Features_s.avx_enabled | val avx_enabled:bool | val avx_enabled:bool | let avx_enabled : bool = avx_cpuid_enabled && avx_xcr0 | {
"file_name": "vale/specs/hardware/Vale.X64.CPU_Features_s.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 81,
"start_col": 0,
"start_line": 81
} | module Vale.X64.CPU_Features_s
open FStar.Mul
open Vale.X64.Machine_s
open Vale.Def.Words_s
(* CPUID *)
assume val aesni_enabled : bool // CPUID.01H:ECX.AESNI[bit 25]
assume val avx_cpuid_enabled : bool // CPUID.01H:ECX.AVX[bit 28]
assume val pclmulqdq_enabled : bool // CPUID.01H:ECX.PCLMULQDQ[bit 1]
assume val avx2_cpuid_enabled : bool // CPUID.7.0.EBX[5]
assume val bmi2_enabled : bool // CPUID.7.0.EBX[8]
assume val avx512f_enabled : bool // CPUID.7.0.EBX[16]
assume val avx512dq_enabled : bool // CPUID.7.0.EBX[17]
assume val adx_enabled : bool // CPUID.7.0.EBX[19]
assume val sha_enabled : bool // CPUID.7.0.EBX[29]
assume val avx512bw_enabled : bool // CPUID.7.0.EBX[30]
assume val avx512vl_enabled : bool // CPUID.7.0.EBX[31]
assume val sse2_enabled : bool // CPUID.01H:EDX.SSE2[bit 26]
assume val ssse3_enabled : bool // CPUID.01H:ECX.SSSE3[bit 9]
assume val sse4_1_enabled : bool // CPUID.01H:ECX.SSE4.1[bit 19]
assume val movbe_enabled : bool // CPUID.01H.ECX.MOVBE[bit 22]
assume val osxsave_enabled : bool // CPUID.01H.ECX.OSXSAVE[bit 27]
assume val rdrand_enabled : bool // CPUID.01H.ECX.RDRAND[bit 30] = 0
let sse_enabled : bool = sse2_enabled && ssse3_enabled && sse4_1_enabled
let avx512_cpuid_enabled : bool =
avx512f_enabled && avx512dq_enabled && avx512bw_enabled && avx512vl_enabled
assume val cpuid (r:reg_64) (rax:nat64) (rcx:nat64) : nat64
assume val cpuid_features (u:unit) :
Lemma ((forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 25) > 0) = aesni_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 28) > 0) = avx_cpuid_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 1) > 0) = pclmulqdq_enabled) /\
(forall rcx . {:pattern (cpuid rRdx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRdx 1 rcx) (pow2_norm 26) > 0) = sse2_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 9) > 0) = ssse3_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 19) > 0) = sse4_1_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 22) > 0) = movbe_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 27) > 0) = osxsave_enabled) /\
(forall rcx . {:pattern (cpuid rRcx 1 rcx)} (Vale.Def.Types_s.iand (cpuid rRcx 1 rcx) (pow2_norm 30) > 0) = rdrand_enabled) /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 5) > 0) = avx2_cpuid_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 8) > 0) = bmi2_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 16) > 0) = avx512f_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 17) > 0) = avx512dq_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 19) > 0) = adx_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 29) > 0) = sha_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 30) > 0) = avx512bw_enabled /\
(Vale.Def.Types_s.iand (cpuid rRbx 7 0) (pow2_norm 31) > 0) = avx512vl_enabled
)
(* Extended Control Registers *)
assume val sse_xcr0_enabled : bool // Bit 1
assume val avx_xcr0_enabled : bool // Bit 2
assume val opmask_xcr0_enabled : bool // Bit 5
assume val zmm_hi256_xcr0_enabled : bool // Bit 6
assume val hi16_zmm_xcr0_enabled : bool // Bit 7
assume val xgetbv (r:reg_64) (rcx:nat64) : nat64
assume val xgetbv_features (u:unit) :
Lemma ((Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 1) > 0) = sse_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 2) > 0) = avx_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 5) > 0) = opmask_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 6) > 0) = zmm_hi256_xcr0_enabled /\
(Vale.Def.Types_s.iand (xgetbv rRax 0) (pow2_norm 7) > 0) = hi16_zmm_xcr0_enabled
)
let avx_xcr0 : bool = sse_xcr0_enabled && avx_xcr0_enabled
let avx512_xcr0 : bool =
avx_xcr0_enabled && opmask_xcr0_enabled && zmm_hi256_xcr0_enabled && hi16_zmm_xcr0_enabled
(* Full AVX detection *) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.Machine_s.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.X64.CPU_Features_s.fst"
} | [
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Prims.op_AmpAmp",
"Vale.X64.CPU_Features_s.avx_cpuid_enabled",
"Vale.X64.CPU_Features_s.avx_xcr0"
] | [] | false | false | false | true | false | let avx_enabled:bool =
| avx_cpuid_enabled && avx_xcr0 | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_nat64_hex | val print_nat64_hex: x:nat{x <= maxint U64} -> FStar.All.ML unit | val print_nat64_hex: x:nat{x <= maxint U64} -> FStar.All.ML unit | let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x)) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 39,
"start_col": 0,
"start_line": 38
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Prims.nat{x <= Lib.IntTypes.maxint Lib.IntTypes.U64} -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.maxint",
"Lib.IntTypes.U64",
"FStar.IO.print_uint64",
"Lib.RawIntTypes.u64_to_UInt64",
"Lib.IntTypes.u64",
"Prims.unit"
] | [] | false | true | false | false | false | let print_nat64_hex x =
| IO.print_uint64 (u64_to_UInt64 (u64 x)) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_nat64_hex_pad | val print_nat64_hex_pad: x:nat{x <= maxint U64} -> FStar.All.ML unit | val print_nat64_hex_pad: x:nat{x <= maxint U64} -> FStar.All.ML unit | let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x)) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 42,
"start_col": 0,
"start_line": 41
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Prims.nat{x <= Lib.IntTypes.maxint Lib.IntTypes.U64} -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.maxint",
"Lib.IntTypes.U64",
"FStar.IO.print_uint64_hex_pad",
"Lib.RawIntTypes.u64_to_UInt64",
"Lib.IntTypes.u64",
"Prims.unit"
] | [] | false | true | false | false | false | let print_nat64_hex_pad x =
| IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x)) | false |
Vale.Arch.Types.fst | Vale.Arch.Types.lemma_reverse_bytes_quad32_64 | val lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src) | val lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src) | let lemma_reverse_bytes_quad32_64 (src orig final:quad32) : Lemma
(requires final == insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0) (reverse_bytes_nat64 (lo64 src)) 1)
(ensures final == reverse_bytes_quad32 src)
=
reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc (==) {
reverse_bytes_quad32 src;
== { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
== {}
four_reverse (Mkfour (reverse_bytes_nat32 x0) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x3));
== {}
Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0);
== { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3)
(reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
== { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc (==) {
reverse_bytes_nat64 (hi64 src);
== { hi64_reveal ()}
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
== { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc (==) {
reverse_bytes_nat64 (lo64 src);
== { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
== {}
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
== { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
() | {
"file_name": "vale/code/arch/Vale.Arch.Types.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 244,
"start_col": 0,
"start_line": 200
} | module Vale.Arch.Types
open FStar.Mul
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open Vale.Arch.TypesNative
open Vale.Lib.Seqs
open Vale.Def.Words_s
open Vale.Def.Words.Two
open FStar.Calc
let lemma_nat_to_two32 () =
assert_norm (forall (x:nat64).{:pattern (nat_to_two 32 x)}
nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ y) (y *^ x)
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ 0) n
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32;
lemma_zero_nth 32;
lemma_equal_nth 32 (n *^ n) 0
let lemma_BitwiseXorCancel64 (n:nat64) =
lemma_ixor_nth_all 64;
lemma_zero_nth 64;
lemma_equal_nth 64 (ixor n n) 0
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32;
lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
let xor_lemmas () =
FStar.Classical.forall_intro_2 lemma_BitwiseXorCommutative;
FStar.Classical.forall_intro lemma_BitwiseXorWithZero;
FStar.Classical.forall_intro lemma_BitwiseXorCancel;
FStar.Classical.forall_intro lemma_BitwiseXorCancel64;
FStar.Classical.forall_intro_3 lemma_BitwiseXorAssociative;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_quad32_xor () =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
xor_lemmas()
(*
let helper (q:quad32) : Lemma (quad32_xor q q == Mkfour 0 0 0 0) =
let q' = quad32_xor q q in
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
// REVIEW: Why are these necessary?
assert (q'.lo0 == nat32_xor q.lo0 q.lo0);
assert (q'.lo1 == nat32_xor q.lo1 q.lo1);
assert (q'.hi2 == nat32_xor q.hi2 q.hi2);
assert (q'.hi3 == nat32_xor q.hi3 q.hi3);
xor_lemmas()
in
FStar.Classical.forall_intro helper
*)
#pop-options
let lemma_reverse_reverse_bytes_nat32 (n:nat32) :
Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n)
=
reverse_bytes_nat32_reveal ();
let r = reverse_seq (nat32_to_be_bytes n) in
be_bytes_to_nat32_to_be_bytes r;
()
#push-options "--max_fuel 3 --initial_fuel 3 --max_ifuel 3 --initial_ifuel 3" // REVIEW: Why do we need this?
let lemma_reverse_bytes_quad32 (q:quad32) =
quad32_xor_reveal ();
reverse_bytes_nat32_reveal ();
reveal_reverse_bytes_quad32 q;
reveal_reverse_bytes_quad32 (reverse_bytes_quad32 q);
()
#pop-options
let lemma_reverse_bytes_nat32 (_:unit) : Lemma
(reverse_bytes_nat32 0 == 0)
=
reverse_bytes_nat32_reveal ();
assert_norm (nat_to_four 8 0 == Mkfour 0 0 0 0);
()
let lemma_reverse_bytes_quad32_zero (_:unit) : Lemma
(let z = Mkfour 0 0 0 0 in
reverse_bytes_quad32 z == z)
=
let z = Mkfour 0 0 0 0 in
calc (==) {
reverse_bytes_quad32 z;
== { reveal_reverse_bytes_quad32 z }
four_reverse (four_map reverse_bytes_nat32 z);
== { lemma_reverse_bytes_nat32() }
z;
};
()
let lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) :
Lemma (ensures reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s)
=
reveal_reverse_bytes_nat32_seq s;
reveal_reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s);
assert (equal (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s)) s)
(*
let lemma_equality_check_helper_two_to_nat_32 (n:two nat32) :
Lemma ( ((n.lo == 0 /\ n.hi == 0) ==> two_to_nat 32 n == 0) /\
( ~(n.lo == 0) \/ (~(n.hi == 0))) ==> ~(two_to_nat 32 n == 0) /\
((n.lo == 0xFFFFFFFF /\ n.hi == 0xFFFFFFFF) <==> two_to_nat 32 n == 0xFFFFFFFFFFFFFFFF))
=
if n.lo == 0 /\ n.hi == 0 then (
assert (int_to_natN pow2_64 (n.lo + pow2_32 * n.hi) == 0);
()
) else (
()
);
()
let lemma_equality_check_helper_lo (q:quad32) :
Lemma ((q.lo0 == 0 /\ q.lo1 == 0 ==> lo64 q == 0) /\
((not (q.lo0 = 0) \/ not (q.lo1 = 0)) ==> not (lo64 q = 0)) /\
(q.lo0 == 0xFFFFFFFF /\ q.lo1 == 0xFFFFFFFF <==> lo64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (lo64 q == two_to_nat 32 (Mktwo q.lo0 q.lo1));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.lo0 q.lo1);
()
let lemma_equality_check_helper_hi (q:quad32) :
Lemma ((q.hi2 == 0 /\ q.hi3 == 0 ==> hi64 q == 0) /\
((~(q.hi2 = 0) \/ ~(q.hi3 = 0)) ==> ~(hi64 q = 0)) /\
(q.hi2 == 0xFFFFFFFF /\ q.hi3 == 0xFFFFFFFF <==> hi64 q == 0xFFFFFFFFFFFFFFFF))
=
assert (hi64 q == two_to_nat 32 (Mktwo q.hi2 q.hi3));
lemma_equality_check_helper_two_to_nat_32 (Mktwo q.hi2 q.hi3);
()
*)
let lemma_insert_nat64_properties (q:quad32) (n:nat64) :
Lemma ( (let q' = insert_nat64 q n 0 in
q'.hi2 == q.hi2 /\
q'.hi3 == q.hi3) /\
(let q' = insert_nat64 q n 1 in
q'.lo0 == q.lo0 /\
q'.lo1 == q.lo1))
=
insert_nat64_reveal ();
()
let lemma_insert_nat64_nat32s (q:quad32) (n0 n1:nat32) :
Lemma ( insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 0 ==
Mkfour n0 n1 q.hi2 q.hi3 /\
insert_nat64 q (two_to_nat32 (Mktwo n0 n1)) 1 ==
Mkfour q.lo0 q.lo1 n0 n1 )
=
let open Vale.Def.Words.Two in
insert_nat64_reveal ();
()
let lemma_lo64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
=
lo64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 0 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 0 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_hi64_properties (_:unit) :
Lemma (forall (q0 q1:quad32) . (q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1))
=
hi64_reveal ();
let helper (q0 q1:quad32) : Lemma ((q0.hi2 == q1.hi2 /\ q0.hi3 == q1.hi3) <==> (hi64 q0 == hi64 q1)) =
let Mktwo n1 n2 = two_select (four_to_two_two q0) 1 in
nat_to_two_to_nat n1 n2;
let Mktwo n1 n2 = two_select (four_to_two_two q1) 1 in
nat_to_two_to_nat n1 n2;
()
in
FStar.Classical.forall_intro_2 helper;
()
let lemma_reverse_bytes_nat64_32 (n0 n1:nat32) : Lemma
(reverse_bytes_nat64 (two_to_nat32 (Mktwo n0 n1)) == two_to_nat32 (Mktwo (reverse_bytes_nat32 n1) (reverse_bytes_nat32 n0)))
=
reverse_bytes_nat64_reveal () | {
"checked_file": "/",
"dependencies": [
"Vale.Lib.Seqs.fsti.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Two.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.TypesNative.fsti.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Classical.fsti.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Vale.Arch.Types.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Calc",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.TypesNative",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Two_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Four_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Seqs_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | src: Vale.Def.Types_s.quad32 -> orig: Vale.Def.Types_s.quad32 -> final: Vale.Def.Types_s.quad32
-> FStar.Pervasives.Lemma
(requires
final ==
Vale.Def.Types_s.insert_nat64 (Vale.Def.Types_s.insert_nat64 orig
(Vale.Def.Types_s.reverse_bytes_nat64 (Vale.Arch.Types.hi64 src))
0)
(Vale.Def.Types_s.reverse_bytes_nat64 (Vale.Arch.Types.lo64 src))
1) (ensures final == Vale.Def.Types_s.reverse_bytes_quad32 src) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Vale.Def.Types_s.quad32",
"Vale.Def.Types_s.nat32",
"Prims.unit",
"FStar.Calc.calc_finish",
"Vale.Def.Types_s.nat64",
"Prims.eq2",
"Vale.Def.Types_s.reverse_bytes_nat64",
"Vale.Arch.Types.lo64",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Vale.Def.Words.Two_s.two_to_nat",
"Vale.Def.Words_s.Mktwo",
"Vale.Def.Words_s.natN",
"Prims.pow2",
"Vale.Def.Words.Two_s.two_select",
"Vale.Def.Words_s.two",
"Vale.Def.Words.Four_s.four_to_two_two",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Vale.Arch.Types.lo64_reveal",
"Prims.squash",
"Vale.Arch.Types.lemma_reverse_bytes_nat64_32",
"Vale.Arch.Types.hi64",
"Vale.Arch.Types.hi64_reveal",
"Vale.Def.Types_s.reverse_bytes_quad32",
"Vale.Def.Types_s.insert_nat64",
"Vale.Def.Words_s.Mkfour",
"Vale.Def.Types_s.reverse_bytes_nat32",
"Vale.Def.Words_s.__proj__Mkfour__item__hi2",
"Vale.Def.Words_s.__proj__Mkfour__item__hi3",
"Vale.Def.Words.Four_s.four_reverse",
"Vale.Def.Words.Four_s.four_map",
"Vale.Def.Types_s.reveal_reverse_bytes_quad32",
"Vale.Arch.Types.lemma_insert_nat64_nat32s",
"Vale.Def.Words_s.nat64",
"Vale.Arch.Types.two_to_nat32",
"Vale.Def.Words_s.nat32",
"Vale.Def.Types_s.reverse_bytes_nat64_reveal",
"FStar.Pervasives.pattern"
] | [] | false | false | true | false | false | let lemma_reverse_bytes_quad32_64 (src orig final: quad32)
: Lemma
(requires
final ==
insert_nat64 (insert_nat64 orig (reverse_bytes_nat64 (hi64 src)) 0)
(reverse_bytes_nat64 (lo64 src))
1) (ensures final == reverse_bytes_quad32 src) =
| reverse_bytes_nat64_reveal ();
let Mkfour x0 x1 x2 x3 = src in
let two32 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2))) in
let two10 = (two_to_nat32 (Mktwo (reverse_bytes_nat32 x1) (reverse_bytes_nat32 x0))) in
calc ( == ) {
reverse_bytes_quad32 src;
( == ) { reveal_reverse_bytes_quad32 src }
four_reverse (four_map reverse_bytes_nat32 src);
( == ) { () }
four_reverse (Mkfour (reverse_bytes_nat32 x0)
(reverse_bytes_nat32 x1)
(reverse_bytes_nat32 x2)
(reverse_bytes_nat32 x3));
( == ) { () }
Mkfour (reverse_bytes_nat32 x3)
(reverse_bytes_nat32 x2)
(reverse_bytes_nat32 x1)
(reverse_bytes_nat32 x0);
( == ) { lemma_insert_nat64_nat32s (Mkfour (reverse_bytes_nat32 x3)
(reverse_bytes_nat32 x2)
orig.hi2
orig.hi3)
(reverse_bytes_nat32 x1)
(reverse_bytes_nat32 x0) }
insert_nat64 (Mkfour (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) orig.hi2 orig.hi3) two10 1;
( == ) { lemma_insert_nat64_nat32s orig (reverse_bytes_nat32 x3) (reverse_bytes_nat32 x2) }
insert_nat64 (insert_nat64 orig two32 0) two10 1;
};
calc ( == ) {
reverse_bytes_nat64 (hi64 src);
( == ) { hi64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 1));
( == ) { () }
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x2 x3));
( == ) { lemma_reverse_bytes_nat64_32 x2 x3 }
two32;
};
calc ( == ) {
reverse_bytes_nat64 (lo64 src);
( == ) { lo64_reveal () }
reverse_bytes_nat64 (two_to_nat 32 (two_select (four_to_two_two src) 0));
( == ) { () }
reverse_bytes_nat64 (two_to_nat 32 (Mktwo x0 x1));
( == ) { lemma_reverse_bytes_nat64_32 x0 x1 }
two10;
};
() | false |
Benton2004.RHL.Derived.fst | Benton2004.RHL.Derived.related | val related : c: Benton2004.computation ->
c': Benton2004.computation ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi': Benton2004.RHL.gexp Prims.bool
-> Type0 | let related c c' phi phi' = exec_equiv phi phi' c c' | {
"file_name": "examples/rel/Benton2004.RHL.Derived.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 52,
"end_line": 88,
"start_col": 0,
"start_line": 88
} | (*
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 Benton2004.RHL.Derived
include Benton2004.RHL
(* Derived rules and patterns *)
let r_ass_derived
(x y: var)
(e e' : exp int)
(p p': gexp bool)
: Lemma
(requires (
included
p
(gsubst (gsubst p' x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
))
(ensures (exec_equiv
p
p'
(assign x e)
(assign y e')
))
[SMTPat (exec_equiv p p' (assign x e) (assign y e'))]
= Benton2004.RHL.r_ass x y e e' p'
let r_dassl_derived
(x: var)
(e: exp int)
(phi phi': gexp bool)
: Lemma
(requires (
included phi (gsubst phi' x Left (exp_to_gexp e Left))
))
(ensures (exec_equiv phi phi' (assign x e) skip))
[SMTPat (exec_equiv phi phi' (assign x e) skip)]
= Benton2004.RHL.r_dassl x e phi'
let flip_flip
(phi: gexp bool)
: Lemma
(forall h1 h2. (flip (flip phi)) h1 h2 == phi h1 h2)
[SMTPat (flip (flip phi))]
= ()
let r_dassr
(x: var)
(e: exp int)
(phi phi' : gexp bool)
: Lemma
(requires (
included phi (gsubst phi' x Right (exp_to_gexp e Right))
))
(ensures (exec_equiv phi phi' skip (assign x e)))
[SMTPat (exec_equiv phi phi' skip (assign x e))]
= r_dassl_derived x e (flip phi) (flip phi')
let d_su1'_flip
(c'' c c' : computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' skip c /\
exec_equiv phi' phi'' c'' c'
))
(ensures (exec_equiv phi phi'' c'' (seq c c')))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' c'' (seq c c')); SMTPat (exec_equiv phi phi' skip c)];
[SMTPat (exec_equiv phi phi'' c'' (seq c c')); SMTPat (exec_equiv phi' phi'' c'' c')];
[SMTPat (exec_equiv phi phi' skip c); SMTPat (exec_equiv phi' phi'' c'' c')];
]]
= d_su1' c c' c'' (flip phi) (flip phi') (flip phi'') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"Benton2004.RHL.fsti.checked"
],
"interface_file": false,
"source_file": "Benton2004.RHL.Derived.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
c: Benton2004.computation ->
c': Benton2004.computation ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi': Benton2004.RHL.gexp Prims.bool
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Benton2004.computation",
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.RHL.exec_equiv"
] | [] | false | false | false | true | true | let related c c' phi phi' =
| exec_equiv phi phi' c c' | false |
|
Lib.PrintSequence.fst | Lib.PrintSequence.print_compare_display_diff | val print_compare_display_diff: display:bool -> len:size_nat -> expected:lbytes len -> result:lbytes len -> FStar.All.ML bool | val print_compare_display_diff: display:bool -> len:size_nat -> expected:lbytes len -> result:lbytes len -> FStar.All.ML bool | let print_compare_display_diff flag len expected result =
let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag then r
else (
let diff = map2 (fun a b -> a ^. b) expected result in
if r then IO.print_string "\nSuccess !"
else begin
IO.print_string "\nFailure !";
IO.print_newline ();
IO.print_string "\nDiff: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list diff);
IO.print_newline ();
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_newline ();
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
IO.print_newline ()
end;
r) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 6,
"end_line": 195,
"start_col": 0,
"start_line": 176
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x)
let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x)
let print_label_nat64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n")
let print_label_uint8 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint8_hex_pad x;
IO.print_string "\n")
let print_label_uint32 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint32_hex_pad x;
IO.print_string "\n")
let print_label_uint64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint64_hex_pad x;
IO.print_string "\n")
let print_list_nat64 flag l =
if not flag then ()
else (
repeat_range_all_ml 0 (List.Tot.length l) (fun i _ ->
print_nat64_dec (List.Tot.index l i);
IO.print_string " "
) ())
let print_string flag s = if flag then IO.print_string s else ()
let print_lbytes flag len b =
if not flag then () else (
let q = 32 in
let n = len / q in
let r = len % q in
if n = 0 then (
List.iter (fun a -> print_uint8_hex_pad a) (to_list b))
else (
repeat_range_all_ml 0 n (fun i _ ->
let sb = sub #uint8 #len b (i * q) q in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb);
(if i < n - 1 then IO.print_string "\n" else ())) ();
(if r <> 0 then IO.print_newline ());
let sb = sub #uint8 #len b (n * q) r in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb)))
let print_label_lbytes flag label len b =
if not flag then () else (
IO.print_string label;
IO.print_string ": \n";
print_lbytes flag len b;
IO.print_newline ())
let print_compare flag len expected result =
let r:bool = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if (not flag) then r else (
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
r)
let print_compare_display flag len expected result =
let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag then r
else (
if r then IO.print_string "\nSuccess !"
else begin
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
IO.print_string "\nFailure !"
end;
r) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 |
display: Prims.bool ->
len: Lib.IntTypes.size_nat ->
expected: Lib.ByteSequence.lbytes len ->
result: Lib.ByteSequence.lbytes len
-> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Lib.IntTypes.size_nat",
"Lib.ByteSequence.lbytes",
"Prims.op_Negation",
"Prims.unit",
"FStar.IO.print_string",
"FStar.IO.print_newline",
"FStar.List.iter",
"Lib.IntTypes.uint8",
"Lib.PrintSequence.print_uint8_hex_pad",
"Lib.Sequence.to_list",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.int_t",
"Lib.Sequence.lseq",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"Lib.Sequence.index",
"Lib.IntTypes.logxor",
"Lib.Sequence.map2",
"Lib.IntTypes.op_Hat_Dot",
"Lib.Sequence.for_all2",
"Prims.op_Equality",
"Prims.l_or",
"Prims.int",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.IntTypes.uint_v",
"Lib.RawIntTypes.uint_to_nat"
] | [] | false | true | false | false | false | let print_compare_display_diff flag len expected result =
| let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag
then r
else
(let diff = map2 (fun a b -> a ^. b) expected result in
if r
then IO.print_string "\nSuccess !"
else
(IO.print_string "\nFailure !";
IO.print_newline ();
IO.print_string "\nDiff: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list diff);
IO.print_newline ();
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_newline ();
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
IO.print_newline ());
r) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_nat64_dec_pad | val print_nat64_dec_pad: x:nat{x <= maxint U64} -> FStar.All.ML unit | val print_nat64_dec_pad: x:nat{x <= maxint U64} -> FStar.All.ML unit | let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x)) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 48,
"start_col": 0,
"start_line": 47
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | x: Prims.nat{x <= Lib.IntTypes.maxint Lib.IntTypes.U64} -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.maxint",
"Lib.IntTypes.U64",
"FStar.IO.print_uint64_dec_pad",
"Lib.RawIntTypes.u64_to_UInt64",
"Lib.IntTypes.u64",
"Prims.unit"
] | [] | false | true | false | false | false | let print_nat64_dec_pad x =
| IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x)) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_compare_display | val print_compare_display: display:bool -> len:size_nat -> expected:lbytes len -> result:lbytes len -> FStar.All.ML bool | val print_compare_display: display:bool -> len:size_nat -> expected:lbytes len -> result:lbytes len -> FStar.All.ML bool | let print_compare_display flag len expected result =
let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag then r
else (
if r then IO.print_string "\nSuccess !"
else begin
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
IO.print_string "\nFailure !"
end;
r) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 6,
"end_line": 174,
"start_col": 0,
"start_line": 162
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x)
let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x)
let print_label_nat64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n")
let print_label_uint8 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint8_hex_pad x;
IO.print_string "\n")
let print_label_uint32 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint32_hex_pad x;
IO.print_string "\n")
let print_label_uint64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint64_hex_pad x;
IO.print_string "\n")
let print_list_nat64 flag l =
if not flag then ()
else (
repeat_range_all_ml 0 (List.Tot.length l) (fun i _ ->
print_nat64_dec (List.Tot.index l i);
IO.print_string " "
) ())
let print_string flag s = if flag then IO.print_string s else ()
let print_lbytes flag len b =
if not flag then () else (
let q = 32 in
let n = len / q in
let r = len % q in
if n = 0 then (
List.iter (fun a -> print_uint8_hex_pad a) (to_list b))
else (
repeat_range_all_ml 0 n (fun i _ ->
let sb = sub #uint8 #len b (i * q) q in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb);
(if i < n - 1 then IO.print_string "\n" else ())) ();
(if r <> 0 then IO.print_newline ());
let sb = sub #uint8 #len b (n * q) r in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb)))
let print_label_lbytes flag label len b =
if not flag then () else (
IO.print_string label;
IO.print_string ": \n";
print_lbytes flag len b;
IO.print_newline ())
let print_compare flag len expected result =
let r:bool = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if (not flag) then r else (
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
r) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 |
display: Prims.bool ->
len: Lib.IntTypes.size_nat ->
expected: Lib.ByteSequence.lbytes len ->
result: Lib.ByteSequence.lbytes len
-> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Lib.IntTypes.size_nat",
"Lib.ByteSequence.lbytes",
"Prims.op_Negation",
"Prims.unit",
"FStar.IO.print_string",
"FStar.List.iter",
"Lib.IntTypes.uint8",
"Lib.PrintSequence.print_uint8_hex_pad",
"Lib.Sequence.to_list",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Sequence.for_all2",
"Prims.op_Equality",
"Prims.nat",
"Prims.l_or",
"Prims.b2t",
"Prims.int",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.IntTypes.uint_v",
"Lib.RawIntTypes.uint_to_nat"
] | [] | false | true | false | false | false | let print_compare_display flag len expected result =
| let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag
then r
else
(if r
then IO.print_string "\nSuccess !"
else
(IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
IO.print_string "\nFailure !");
r) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_compare | val print_compare: display:bool -> len:size_nat -> expected:lbytes len -> result:lbytes len -> FStar.All.ML bool | val print_compare: display:bool -> len:size_nat -> expected:lbytes len -> result:lbytes len -> FStar.All.ML bool | let print_compare flag len expected result =
let r:bool = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if (not flag) then r else (
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
r) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 160,
"start_col": 0,
"start_line": 153
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x)
let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x)
let print_label_nat64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n")
let print_label_uint8 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint8_hex_pad x;
IO.print_string "\n")
let print_label_uint32 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint32_hex_pad x;
IO.print_string "\n")
let print_label_uint64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint64_hex_pad x;
IO.print_string "\n")
let print_list_nat64 flag l =
if not flag then ()
else (
repeat_range_all_ml 0 (List.Tot.length l) (fun i _ ->
print_nat64_dec (List.Tot.index l i);
IO.print_string " "
) ())
let print_string flag s = if flag then IO.print_string s else ()
let print_lbytes flag len b =
if not flag then () else (
let q = 32 in
let n = len / q in
let r = len % q in
if n = 0 then (
List.iter (fun a -> print_uint8_hex_pad a) (to_list b))
else (
repeat_range_all_ml 0 n (fun i _ ->
let sb = sub #uint8 #len b (i * q) q in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb);
(if i < n - 1 then IO.print_string "\n" else ())) ();
(if r <> 0 then IO.print_newline ());
let sb = sub #uint8 #len b (n * q) r in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb)))
let print_label_lbytes flag label len b =
if not flag then () else (
IO.print_string label;
IO.print_string ": \n";
print_lbytes flag len b;
IO.print_newline ()) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 |
display: Prims.bool ->
len: Lib.IntTypes.size_nat ->
expected: Lib.ByteSequence.lbytes len ->
result: Lib.ByteSequence.lbytes len
-> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Lib.IntTypes.size_nat",
"Lib.ByteSequence.lbytes",
"Prims.op_Negation",
"Prims.unit",
"FStar.List.iter",
"Lib.IntTypes.uint8",
"Lib.PrintSequence.print_uint8_hex_pad",
"Lib.Sequence.to_list",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.IO.print_string",
"Lib.Sequence.for_all2",
"Prims.op_Equality",
"Prims.nat",
"Prims.l_or",
"Prims.b2t",
"Prims.int",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.IntTypes.uint_v",
"Lib.RawIntTypes.uint_to_nat"
] | [] | false | true | false | false | false | let print_compare flag len expected result =
| let r:bool = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if (not flag)
then r
else
(IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
r) | false |
Benton2004.RHL.Derived.fst | Benton2004.RHL.Derived.r_ass_derived | val r_ass_derived (x y: var) (e e': exp int) (p p': gexp bool)
: Lemma
(requires
(included p (gsubst (gsubst p' x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right)))
)
(ensures (exec_equiv p p' (assign x e) (assign y e')))
[SMTPat (exec_equiv p p' (assign x e) (assign y e'))] | val r_ass_derived (x y: var) (e e': exp int) (p p': gexp bool)
: Lemma
(requires
(included p (gsubst (gsubst p' x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right)))
)
(ensures (exec_equiv p p' (assign x e) (assign y e')))
[SMTPat (exec_equiv p p' (assign x e) (assign y e'))] | let r_ass_derived
(x y: var)
(e e' : exp int)
(p p': gexp bool)
: Lemma
(requires (
included
p
(gsubst (gsubst p' x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
))
(ensures (exec_equiv
p
p'
(assign x e)
(assign y e')
))
[SMTPat (exec_equiv p p' (assign x e) (assign y e'))]
= Benton2004.RHL.r_ass x y e e' p' | {
"file_name": "examples/rel/Benton2004.RHL.Derived.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 38,
"start_col": 0,
"start_line": 21
} | (*
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 Benton2004.RHL.Derived
include Benton2004.RHL
(* Derived rules and patterns *) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"Benton2004.RHL.fsti.checked"
],
"interface_file": false,
"source_file": "Benton2004.RHL.Derived.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: Benton2004.var ->
y: Benton2004.var ->
e: Benton2004.exp Prims.int ->
e': Benton2004.exp Prims.int ->
p: Benton2004.RHL.gexp Prims.bool ->
p': Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.included p
(Benton2004.RHL.gsubst (Benton2004.RHL.gsubst p'
x
Benton2004.RHL.Left
(Benton2004.RHL.exp_to_gexp e Benton2004.RHL.Left))
y
Benton2004.RHL.Right
(Benton2004.RHL.exp_to_gexp e' Benton2004.RHL.Right)))
(ensures Benton2004.RHL.exec_equiv p p' (Benton2004.assign x e) (Benton2004.assign y e'))
[SMTPat (Benton2004.RHL.exec_equiv p p' (Benton2004.assign x e) (Benton2004.assign y e'))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.var",
"Benton2004.exp",
"Prims.int",
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.RHL.r_ass",
"Prims.unit",
"Benton2004.RHL.included",
"Benton2004.RHL.gsubst",
"Benton2004.RHL.Left",
"Benton2004.RHL.exp_to_gexp",
"Benton2004.RHL.Right",
"Prims.squash",
"Benton2004.RHL.exec_equiv",
"Benton2004.assign",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let r_ass_derived (x y: var) (e e': exp int) (p p': gexp bool)
: Lemma
(requires
(included p (gsubst (gsubst p' x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right)))
)
(ensures (exec_equiv p p' (assign x e) (assign y e')))
[SMTPat (exec_equiv p p' (assign x e) (assign y e'))] =
| Benton2004.RHL.r_ass x y e e' p' | false |
Benton2004.RHL.Derived.fst | Benton2004.RHL.Derived.r_dassl_derived | val r_dassl_derived (x: var) (e: exp int) (phi phi': gexp bool)
: Lemma (requires (included phi (gsubst phi' x Left (exp_to_gexp e Left))))
(ensures (exec_equiv phi phi' (assign x e) skip))
[SMTPat (exec_equiv phi phi' (assign x e) skip)] | val r_dassl_derived (x: var) (e: exp int) (phi phi': gexp bool)
: Lemma (requires (included phi (gsubst phi' x Left (exp_to_gexp e Left))))
(ensures (exec_equiv phi phi' (assign x e) skip))
[SMTPat (exec_equiv phi phi' (assign x e) skip)] | let r_dassl_derived
(x: var)
(e: exp int)
(phi phi': gexp bool)
: Lemma
(requires (
included phi (gsubst phi' x Left (exp_to_gexp e Left))
))
(ensures (exec_equiv phi phi' (assign x e) skip))
[SMTPat (exec_equiv phi phi' (assign x e) skip)]
= Benton2004.RHL.r_dassl x e phi' | {
"file_name": "examples/rel/Benton2004.RHL.Derived.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 33,
"end_line": 50,
"start_col": 0,
"start_line": 40
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL.Derived
include Benton2004.RHL
(* Derived rules and patterns *)
let r_ass_derived
(x y: var)
(e e' : exp int)
(p p': gexp bool)
: Lemma
(requires (
included
p
(gsubst (gsubst p' x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
))
(ensures (exec_equiv
p
p'
(assign x e)
(assign y e')
))
[SMTPat (exec_equiv p p' (assign x e) (assign y e'))]
= Benton2004.RHL.r_ass x y e e' p' | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"Benton2004.RHL.fsti.checked"
],
"interface_file": false,
"source_file": "Benton2004.RHL.Derived.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: Benton2004.var ->
e: Benton2004.exp Prims.int ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi': Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.included phi
(Benton2004.RHL.gsubst phi'
x
Benton2004.RHL.Left
(Benton2004.RHL.exp_to_gexp e Benton2004.RHL.Left)))
(ensures Benton2004.RHL.exec_equiv phi phi' (Benton2004.assign x e) Benton2004.skip)
[SMTPat (Benton2004.RHL.exec_equiv phi phi' (Benton2004.assign x e) Benton2004.skip)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.var",
"Benton2004.exp",
"Prims.int",
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.RHL.r_dassl",
"Prims.unit",
"Benton2004.RHL.included",
"Benton2004.RHL.gsubst",
"Benton2004.RHL.Left",
"Benton2004.RHL.exp_to_gexp",
"Prims.squash",
"Benton2004.RHL.exec_equiv",
"Benton2004.assign",
"Benton2004.skip",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let r_dassl_derived (x: var) (e: exp int) (phi phi': gexp bool)
: Lemma (requires (included phi (gsubst phi' x Left (exp_to_gexp e Left))))
(ensures (exec_equiv phi phi' (assign x e) skip))
[SMTPat (exec_equiv phi phi' (assign x e) skip)] =
| Benton2004.RHL.r_dassl x e phi' | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_list_nat64 | val print_list_nat64: display:bool -> list size_nat -> FStar.All.ML unit | val print_list_nat64: display:bool -> list size_nat -> FStar.All.ML unit | let print_list_nat64 flag l =
if not flag then ()
else (
repeat_range_all_ml 0 (List.Tot.length l) (fun i _ ->
print_nat64_dec (List.Tot.index l i);
IO.print_string " "
) ()) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 125,
"start_col": 0,
"start_line": 119
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x)
let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x)
let print_label_nat64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n")
let print_label_uint8 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint8_hex_pad x;
IO.print_string "\n")
let print_label_uint32 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint32_hex_pad x;
IO.print_string "\n")
let print_label_uint64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint64_hex_pad x;
IO.print_string "\n") | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | display: Prims.bool -> l: Prims.list Lib.IntTypes.size_nat -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Prims.list",
"Lib.IntTypes.size_nat",
"Prims.op_Negation",
"Prims.unit",
"Lib.LoopCombinators.repeat_range_all_ml",
"FStar.List.Tot.Base.length",
"Prims.nat",
"Prims.l_and",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Prims.op_LessThan",
"FStar.IO.print_string",
"Lib.PrintSequence.print_nat64_dec",
"FStar.List.Tot.Base.index"
] | [] | false | true | false | false | false | let print_list_nat64 flag l =
| if not flag
then ()
else
(repeat_range_all_ml 0
(List.Tot.length l)
(fun i _ ->
print_nat64_dec (List.Tot.index l i);
IO.print_string " ")
()) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_lbytes | val print_lbytes: display:bool -> len:size_nat -> lbytes len -> FStar.All.ML unit | val print_lbytes: display:bool -> len:size_nat -> lbytes len -> FStar.All.ML unit | let print_lbytes flag len b =
if not flag then () else (
let q = 32 in
let n = len / q in
let r = len % q in
if n = 0 then (
List.iter (fun a -> print_uint8_hex_pad a) (to_list b))
else (
repeat_range_all_ml 0 n (fun i _ ->
let sb = sub #uint8 #len b (i * q) q in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb);
(if i < n - 1 then IO.print_string "\n" else ())) ();
(if r <> 0 then IO.print_newline ());
let sb = sub #uint8 #len b (n * q) r in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb))) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 59,
"end_line": 144,
"start_col": 0,
"start_line": 130
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x)
let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x)
let print_label_nat64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n")
let print_label_uint8 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint8_hex_pad x;
IO.print_string "\n")
let print_label_uint32 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint32_hex_pad x;
IO.print_string "\n")
let print_label_uint64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint64_hex_pad x;
IO.print_string "\n")
let print_list_nat64 flag l =
if not flag then ()
else (
repeat_range_all_ml 0 (List.Tot.length l) (fun i _ ->
print_nat64_dec (List.Tot.index l i);
IO.print_string " "
) ())
let print_string flag s = if flag then IO.print_string s else () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 | display: Prims.bool -> len: Lib.IntTypes.size_nat -> b: Lib.ByteSequence.lbytes len
-> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Lib.IntTypes.size_nat",
"Lib.ByteSequence.lbytes",
"Prims.op_Negation",
"Prims.unit",
"Prims.op_Equality",
"Prims.int",
"FStar.List.iter",
"Lib.IntTypes.uint8",
"Lib.PrintSequence.print_uint8_hex_pad",
"Lib.Sequence.to_list",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.op_Multiply",
"Prims.op_Addition",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.Sequence.sub",
"FStar.Mul.op_Star",
"Prims.op_disEquality",
"FStar.IO.print_newline",
"Lib.LoopCombinators.repeat_range_all_ml",
"Prims.op_GreaterThanOrEqual",
"Prims.op_Subtraction",
"FStar.IO.print_string",
"Prims.op_Modulus",
"Prims.op_Division"
] | [] | false | true | false | false | false | let print_lbytes flag len b =
| if not flag
then ()
else
(let q = 32 in
let n = len / q in
let r = len % q in
if n = 0
then (List.iter (fun a -> print_uint8_hex_pad a) (to_list b))
else
(repeat_range_all_ml 0
n
(fun i _ ->
let sb = sub #uint8 #len b (i * q) q in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb);
(if i < n - 1 then IO.print_string "\n"))
();
(if r <> 0 then IO.print_newline ());
let sb = sub #uint8 #len b (n * q) r in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb))) | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_label_compare_display_diff | val print_label_compare_display_diff: display:bool -> s:string -> len:size_nat -> expected:lbytes len -> result:lbytes len -> FStar.All.ML bool | val print_label_compare_display_diff: display:bool -> s:string -> len:size_nat -> expected:lbytes len -> result:lbytes len -> FStar.All.ML bool | let print_label_compare_display_diff flag s len expected result =
let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag then r
else (
let diff = map2 (fun a b -> a ^. b) expected result in
if r then (
IO.print_string "\nSuccess ! ";
IO.print_string s;
IO.print_newline ())
else begin
IO.print_string "\nFailure ! ";
IO.print_string s;
IO.print_newline ();
IO.print_string "\nDiff: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list diff);
IO.print_newline ();
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_newline ();
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
IO.print_newline ()
end;
r) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 6,
"end_line": 238,
"start_col": 0,
"start_line": 215
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x)
let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x)
let print_label_nat64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n")
let print_label_uint8 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint8_hex_pad x;
IO.print_string "\n")
let print_label_uint32 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint32_hex_pad x;
IO.print_string "\n")
let print_label_uint64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint64_hex_pad x;
IO.print_string "\n")
let print_list_nat64 flag l =
if not flag then ()
else (
repeat_range_all_ml 0 (List.Tot.length l) (fun i _ ->
print_nat64_dec (List.Tot.index l i);
IO.print_string " "
) ())
let print_string flag s = if flag then IO.print_string s else ()
let print_lbytes flag len b =
if not flag then () else (
let q = 32 in
let n = len / q in
let r = len % q in
if n = 0 then (
List.iter (fun a -> print_uint8_hex_pad a) (to_list b))
else (
repeat_range_all_ml 0 n (fun i _ ->
let sb = sub #uint8 #len b (i * q) q in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb);
(if i < n - 1 then IO.print_string "\n" else ())) ();
(if r <> 0 then IO.print_newline ());
let sb = sub #uint8 #len b (n * q) r in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb)))
let print_label_lbytes flag label len b =
if not flag then () else (
IO.print_string label;
IO.print_string ": \n";
print_lbytes flag len b;
IO.print_newline ())
let print_compare flag len expected result =
let r:bool = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if (not flag) then r else (
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
r)
let print_compare_display flag len expected result =
let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag then r
else (
if r then IO.print_string "\nSuccess !"
else begin
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
IO.print_string "\nFailure !"
end;
r)
let print_compare_display_diff flag len expected result =
let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag then r
else (
let diff = map2 (fun a b -> a ^. b) expected result in
if r then IO.print_string "\nSuccess !"
else begin
IO.print_string "\nFailure !";
IO.print_newline ();
IO.print_string "\nDiff: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list diff);
IO.print_newline ();
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_newline ();
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
IO.print_newline ()
end;
r)
let print_label_compare_display flag s len expected result =
let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag then r
else (
if r then (
IO.print_string "\nSuccess ! ";
IO.print_string s)
else begin
IO.print_string "\nFailure ! ";
IO.print_string s;
IO.print_newline ();
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected)
end;
r) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 |
display: Prims.bool ->
s: Prims.string ->
len: Lib.IntTypes.size_nat ->
expected: Lib.ByteSequence.lbytes len ->
result: Lib.ByteSequence.lbytes len
-> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Prims.string",
"Lib.IntTypes.size_nat",
"Lib.ByteSequence.lbytes",
"Prims.op_Negation",
"Prims.unit",
"FStar.IO.print_newline",
"FStar.IO.print_string",
"FStar.List.iter",
"Lib.IntTypes.uint8",
"Lib.PrintSequence.print_uint8_hex_pad",
"Lib.Sequence.to_list",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.int_t",
"Lib.Sequence.lseq",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.eq2",
"Lib.Sequence.index",
"Lib.IntTypes.logxor",
"Lib.Sequence.map2",
"Lib.IntTypes.op_Hat_Dot",
"Lib.Sequence.for_all2",
"Prims.op_Equality",
"Prims.l_or",
"Prims.int",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.IntTypes.uint_v",
"Lib.RawIntTypes.uint_to_nat"
] | [] | false | true | false | false | false | let print_label_compare_display_diff flag s len expected result =
| let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag
then r
else
(let diff = map2 (fun a b -> a ^. b) expected result in
if r
then
(IO.print_string "\nSuccess ! ";
IO.print_string s;
IO.print_newline ())
else
(IO.print_string "\nFailure ! ";
IO.print_string s;
IO.print_newline ();
IO.print_string "\nDiff: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list diff);
IO.print_newline ();
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_newline ();
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
IO.print_newline ());
r) | false |
Benton2004.RHL.Derived.fst | Benton2004.RHL.Derived.r_dassr | val r_dassr (x: var) (e: exp int) (phi phi': gexp bool)
: Lemma (requires (included phi (gsubst phi' x Right (exp_to_gexp e Right))))
(ensures (exec_equiv phi phi' skip (assign x e)))
[SMTPat (exec_equiv phi phi' skip (assign x e))] | val r_dassr (x: var) (e: exp int) (phi phi': gexp bool)
: Lemma (requires (included phi (gsubst phi' x Right (exp_to_gexp e Right))))
(ensures (exec_equiv phi phi' skip (assign x e)))
[SMTPat (exec_equiv phi phi' skip (assign x e))] | let r_dassr
(x: var)
(e: exp int)
(phi phi' : gexp bool)
: Lemma
(requires (
included phi (gsubst phi' x Right (exp_to_gexp e Right))
))
(ensures (exec_equiv phi phi' skip (assign x e)))
[SMTPat (exec_equiv phi phi' skip (assign x e))]
= r_dassl_derived x e (flip phi) (flip phi') | {
"file_name": "examples/rel/Benton2004.RHL.Derived.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 44,
"end_line": 69,
"start_col": 0,
"start_line": 59
} | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Benton2004.RHL.Derived
include Benton2004.RHL
(* Derived rules and patterns *)
let r_ass_derived
(x y: var)
(e e' : exp int)
(p p': gexp bool)
: Lemma
(requires (
included
p
(gsubst (gsubst p' x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
))
(ensures (exec_equiv
p
p'
(assign x e)
(assign y e')
))
[SMTPat (exec_equiv p p' (assign x e) (assign y e'))]
= Benton2004.RHL.r_ass x y e e' p'
let r_dassl_derived
(x: var)
(e: exp int)
(phi phi': gexp bool)
: Lemma
(requires (
included phi (gsubst phi' x Left (exp_to_gexp e Left))
))
(ensures (exec_equiv phi phi' (assign x e) skip))
[SMTPat (exec_equiv phi phi' (assign x e) skip)]
= Benton2004.RHL.r_dassl x e phi'
let flip_flip
(phi: gexp bool)
: Lemma
(forall h1 h2. (flip (flip phi)) h1 h2 == phi h1 h2)
[SMTPat (flip (flip phi))]
= () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"Benton2004.RHL.fsti.checked"
],
"interface_file": false,
"source_file": "Benton2004.RHL.Derived.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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: Benton2004.var ->
e: Benton2004.exp Prims.int ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi': Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.included phi
(Benton2004.RHL.gsubst phi'
x
Benton2004.RHL.Right
(Benton2004.RHL.exp_to_gexp e Benton2004.RHL.Right)))
(ensures Benton2004.RHL.exec_equiv phi phi' Benton2004.skip (Benton2004.assign x e))
[SMTPat (Benton2004.RHL.exec_equiv phi phi' Benton2004.skip (Benton2004.assign x e))] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.var",
"Benton2004.exp",
"Prims.int",
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.RHL.Derived.r_dassl_derived",
"Benton2004.RHL.flip",
"Prims.unit",
"Benton2004.RHL.included",
"Benton2004.RHL.gsubst",
"Benton2004.RHL.Right",
"Benton2004.RHL.exp_to_gexp",
"Prims.squash",
"Benton2004.RHL.exec_equiv",
"Benton2004.skip",
"Benton2004.assign",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let r_dassr (x: var) (e: exp int) (phi phi': gexp bool)
: Lemma (requires (included phi (gsubst phi' x Right (exp_to_gexp e Right))))
(ensures (exec_equiv phi phi' skip (assign x e)))
[SMTPat (exec_equiv phi phi' skip (assign x e))] =
| r_dassl_derived x e (flip phi) (flip phi') | false |
Benton2004.RHL.Derived.fst | Benton2004.RHL.Derived.d_su1'_flip | val d_su1'_flip (c'' c c': computation) (phi phi' phi'': gexp bool)
: Lemma (requires (exec_equiv phi phi' skip c /\ exec_equiv phi' phi'' c'' c'))
(ensures (exec_equiv phi phi'' c'' (seq c c')))
[
SMTPatOr
[
[SMTPat (exec_equiv phi phi'' c'' (seq c c')); SMTPat (exec_equiv phi phi' skip c)];
[SMTPat (exec_equiv phi phi'' c'' (seq c c')); SMTPat (exec_equiv phi' phi'' c'' c')];
[SMTPat (exec_equiv phi phi' skip c); SMTPat (exec_equiv phi' phi'' c'' c')]
]
] | val d_su1'_flip (c'' c c': computation) (phi phi' phi'': gexp bool)
: Lemma (requires (exec_equiv phi phi' skip c /\ exec_equiv phi' phi'' c'' c'))
(ensures (exec_equiv phi phi'' c'' (seq c c')))
[
SMTPatOr
[
[SMTPat (exec_equiv phi phi'' c'' (seq c c')); SMTPat (exec_equiv phi phi' skip c)];
[SMTPat (exec_equiv phi phi'' c'' (seq c c')); SMTPat (exec_equiv phi' phi'' c'' c')];
[SMTPat (exec_equiv phi phi' skip c); SMTPat (exec_equiv phi' phi'' c'' c')]
]
] | let d_su1'_flip
(c'' c c' : computation)
(phi phi' phi'' : gexp bool)
: Lemma
(requires (
exec_equiv phi phi' skip c /\
exec_equiv phi' phi'' c'' c'
))
(ensures (exec_equiv phi phi'' c'' (seq c c')))
[SMTPatOr [
[SMTPat (exec_equiv phi phi'' c'' (seq c c')); SMTPat (exec_equiv phi phi' skip c)];
[SMTPat (exec_equiv phi phi'' c'' (seq c c')); SMTPat (exec_equiv phi' phi'' c'' c')];
[SMTPat (exec_equiv phi phi' skip c); SMTPat (exec_equiv phi' phi'' c'' c')];
]]
= d_su1' c c' c'' (flip phi) (flip phi') (flip phi'') | {
"file_name": "examples/rel/Benton2004.RHL.Derived.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 85,
"start_col": 0,
"start_line": 71
} | (*
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 Benton2004.RHL.Derived
include Benton2004.RHL
(* Derived rules and patterns *)
let r_ass_derived
(x y: var)
(e e' : exp int)
(p p': gexp bool)
: Lemma
(requires (
included
p
(gsubst (gsubst p' x Left (exp_to_gexp e Left)) y Right (exp_to_gexp e' Right))
))
(ensures (exec_equiv
p
p'
(assign x e)
(assign y e')
))
[SMTPat (exec_equiv p p' (assign x e) (assign y e'))]
= Benton2004.RHL.r_ass x y e e' p'
let r_dassl_derived
(x: var)
(e: exp int)
(phi phi': gexp bool)
: Lemma
(requires (
included phi (gsubst phi' x Left (exp_to_gexp e Left))
))
(ensures (exec_equiv phi phi' (assign x e) skip))
[SMTPat (exec_equiv phi phi' (assign x e) skip)]
= Benton2004.RHL.r_dassl x e phi'
let flip_flip
(phi: gexp bool)
: Lemma
(forall h1 h2. (flip (flip phi)) h1 h2 == phi h1 h2)
[SMTPat (flip (flip phi))]
= ()
let r_dassr
(x: var)
(e: exp int)
(phi phi' : gexp bool)
: Lemma
(requires (
included phi (gsubst phi' x Right (exp_to_gexp e Right))
))
(ensures (exec_equiv phi phi' skip (assign x e)))
[SMTPat (exec_equiv phi phi' skip (assign x e))]
= r_dassl_derived x e (flip phi) (flip phi') | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Pervasives.fsti.checked",
"Benton2004.RHL.fsti.checked"
],
"interface_file": false,
"source_file": "Benton2004.RHL.Derived.fst"
} | [
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "Benton2004.RHL",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
c'': Benton2004.computation ->
c: Benton2004.computation ->
c': Benton2004.computation ->
phi: Benton2004.RHL.gexp Prims.bool ->
phi': Benton2004.RHL.gexp Prims.bool ->
phi'': Benton2004.RHL.gexp Prims.bool
-> FStar.Pervasives.Lemma
(requires
Benton2004.RHL.exec_equiv phi phi' Benton2004.skip c /\
Benton2004.RHL.exec_equiv phi' phi'' c'' c')
(ensures Benton2004.RHL.exec_equiv phi phi'' c'' (Benton2004.seq c c'))
[
SMTPatOr [
[
SMTPat (Benton2004.RHL.exec_equiv phi phi'' c'' (Benton2004.seq c c'));
SMTPat (Benton2004.RHL.exec_equiv phi phi' Benton2004.skip c)
];
[
SMTPat (Benton2004.RHL.exec_equiv phi phi'' c'' (Benton2004.seq c c'));
SMTPat (Benton2004.RHL.exec_equiv phi' phi'' c'' c')
];
[
SMTPat (Benton2004.RHL.exec_equiv phi phi' Benton2004.skip c);
SMTPat (Benton2004.RHL.exec_equiv phi' phi'' c'' c')
]
]
] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Benton2004.computation",
"Benton2004.RHL.gexp",
"Prims.bool",
"Benton2004.RHL.d_su1'",
"Benton2004.RHL.flip",
"Prims.unit",
"Prims.l_and",
"Benton2004.RHL.exec_equiv",
"Benton2004.skip",
"Prims.squash",
"Benton2004.seq",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat_or",
"Prims.list",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | true | false | true | false | false | let d_su1'_flip (c'' c c': computation) (phi phi' phi'': gexp bool)
: Lemma (requires (exec_equiv phi phi' skip c /\ exec_equiv phi' phi'' c'' c'))
(ensures (exec_equiv phi phi'' c'' (seq c c')))
[
SMTPatOr
[
[SMTPat (exec_equiv phi phi'' c'' (seq c c')); SMTPat (exec_equiv phi phi' skip c)];
[SMTPat (exec_equiv phi phi'' c'' (seq c c')); SMTPat (exec_equiv phi' phi'' c'' c')];
[SMTPat (exec_equiv phi phi' skip c); SMTPat (exec_equiv phi' phi'' c'' c')]
]
] =
| d_su1' c c' c'' (flip phi) (flip phi') (flip phi'') | false |
Lib.PrintSequence.fst | Lib.PrintSequence.print_label_compare_display | val print_label_compare_display: display:bool -> s:string -> len:size_nat -> expected:lbytes len -> result:lbytes len -> FStar.All.ML bool | val print_label_compare_display: display:bool -> s:string -> len:size_nat -> expected:lbytes len -> result:lbytes len -> FStar.All.ML bool | let print_label_compare_display flag s len expected result =
let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag then r
else (
if r then (
IO.print_string "\nSuccess ! ";
IO.print_string s)
else begin
IO.print_string "\nFailure ! ";
IO.print_string s;
IO.print_newline ();
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected)
end;
r) | {
"file_name": "lib/Lib.PrintSequence.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 6,
"end_line": 213,
"start_col": 0,
"start_line": 197
} | module Lib.PrintSequence
open FStar.Mul
open Lib.IntTypes
open Lib.RawIntTypes
open Lib.Sequence
open Lib.ByteSequence
open Lib.LoopCombinators
let print_nat8_hex x =
IO.print_uint8 (u8_to_UInt8 (u8 x))
let print_nat8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 (u8 x))
let print_nat8_dec x =
IO.print_uint8_dec (u8_to_UInt8 (u8 x))
let print_nat8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 (u8 x))
let print_nat32_hex x =
IO.print_uint32 (u32_to_UInt32 (u32 x))
let print_nat32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 (u32 x))
let print_nat32_dec x =
IO.print_uint32_dec (u32_to_UInt32 (u32 x))
let print_nat32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 (u32 x))
let print_nat64_hex x =
IO.print_uint64 (u64_to_UInt64 (u64 x))
let print_nat64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 (u64 x))
let print_nat64_dec x =
IO.print_uint64_dec (u64_to_UInt64 (u64 x))
let print_nat64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 (u64 x))
let print_uint8_hex x =
IO.print_uint8 (u8_to_UInt8 x)
let print_uint8_hex_pad x =
IO.print_uint8_hex_pad (u8_to_UInt8 x)
let print_uint8_dec x =
IO.print_uint8_dec (u8_to_UInt8 x)
let print_uint8_dec_pad x =
IO.print_uint8_dec_pad (u8_to_UInt8 x)
let print_uint32_hex x =
IO.print_uint32 (u32_to_UInt32 x)
let print_uint32_hex_pad x =
IO.print_uint32_hex_pad (u32_to_UInt32 x)
let print_uint32_dec x =
IO.print_uint32_dec (u32_to_UInt32 x)
let print_uint32_dec_pad x =
IO.print_uint32_dec_pad (u32_to_UInt32 x)
let print_uint64_hex x =
IO.print_uint64 (u64_to_UInt64 x)
let print_uint64_hex_pad x =
IO.print_uint64_hex_pad (u64_to_UInt64 x)
let print_uint64_dec x =
IO.print_uint64_dec (u64_to_UInt64 x)
let print_uint64_dec_pad x =
IO.print_uint64_dec_pad (u64_to_UInt64 x)
let print_label_nat64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_nat64_dec x;
IO.print_string "\n")
let print_label_uint8 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint8_hex_pad x;
IO.print_string "\n")
let print_label_uint32 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint32_hex_pad x;
IO.print_string "\n")
let print_label_uint64 flag s x =
if not flag then () else (
IO.print_string s;
IO.print_string ": ";
print_uint64_hex_pad x;
IO.print_string "\n")
let print_list_nat64 flag l =
if not flag then ()
else (
repeat_range_all_ml 0 (List.Tot.length l) (fun i _ ->
print_nat64_dec (List.Tot.index l i);
IO.print_string " "
) ())
let print_string flag s = if flag then IO.print_string s else ()
let print_lbytes flag len b =
if not flag then () else (
let q = 32 in
let n = len / q in
let r = len % q in
if n = 0 then (
List.iter (fun a -> print_uint8_hex_pad a) (to_list b))
else (
repeat_range_all_ml 0 n (fun i _ ->
let sb = sub #uint8 #len b (i * q) q in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb);
(if i < n - 1 then IO.print_string "\n" else ())) ();
(if r <> 0 then IO.print_newline ());
let sb = sub #uint8 #len b (n * q) r in
List.iter (fun a -> print_uint8_hex_pad a) (to_list sb)))
let print_label_lbytes flag label len b =
if not flag then () else (
IO.print_string label;
IO.print_string ": \n";
print_lbytes flag len b;
IO.print_newline ())
let print_compare flag len expected result =
let r:bool = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if (not flag) then r else (
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
r)
let print_compare_display flag len expected result =
let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag then r
else (
if r then IO.print_string "\nSuccess !"
else begin
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
IO.print_string "\nFailure !"
end;
r)
let print_compare_display_diff flag len expected result =
let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag then r
else (
let diff = map2 (fun a b -> a ^. b) expected result in
if r then IO.print_string "\nSuccess !"
else begin
IO.print_string "\nFailure !";
IO.print_newline ();
IO.print_string "\nDiff: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list diff);
IO.print_newline ();
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_newline ();
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected);
IO.print_newline ()
end;
r) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked"
],
"interface_file": true,
"source_file": "Lib.PrintSequence.fst"
} | [
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteSequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.RawIntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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 |
display: Prims.bool ->
s: Prims.string ->
len: Lib.IntTypes.size_nat ->
expected: Lib.ByteSequence.lbytes len ->
result: Lib.ByteSequence.lbytes len
-> FStar.All.ML Prims.bool | FStar.All.ML | [
"ml"
] | [] | [
"Prims.bool",
"Prims.string",
"Lib.IntTypes.size_nat",
"Lib.ByteSequence.lbytes",
"Prims.op_Negation",
"Prims.unit",
"FStar.IO.print_string",
"FStar.List.iter",
"Lib.IntTypes.uint8",
"Lib.PrintSequence.print_uint8_hex_pad",
"Lib.Sequence.to_list",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.IO.print_newline",
"Lib.Sequence.for_all2",
"Prims.op_Equality",
"Prims.nat",
"Prims.l_or",
"Prims.b2t",
"Prims.int",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.range",
"Lib.IntTypes.uint_v",
"Lib.RawIntTypes.uint_to_nat"
] | [] | false | true | false | false | false | let print_label_compare_display flag s len expected result =
| let r = for_all2 (fun a b -> uint_to_nat #U8 a = uint_to_nat #U8 b) expected result in
if not flag
then r
else
(if r
then
(IO.print_string "\nSuccess ! ";
IO.print_string s)
else
(IO.print_string "\nFailure ! ";
IO.print_string s;
IO.print_newline ();
IO.print_string "\nResult: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list result);
IO.print_string "\nExpected: ";
List.iter (fun a -> print_uint8_hex_pad a) (to_list expected));
r) | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.