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
FStar.UInt8.fsti
FStar.UInt8.op_Star_Hat
val op_Star_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
let op_Star_Hat = mul
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 322, "start_col": 7, "start_line": 322 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.mul" ]
[]
false
false
false
false
false
let op_Star_Hat =
mul
false
FStar.UInt8.fsti
FStar.UInt8.op_Star_Percent_Hat
val op_Star_Percent_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
let op_Star_Percent_Hat = mul_mod
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 324, "start_col": 7, "start_line": 324 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.mul_mod" ]
[]
false
false
false
false
false
let op_Star_Percent_Hat =
mul_mod
false
Lib.NatMod.fst
Lib.NatMod.lemma_mul_mod_prime_zero
val lemma_mul_mod_prime_zero: #m:prime -> a:nat_mod m -> b:nat_mod m -> Lemma (a * b % m == 0 <==> (a % m == 0 \/ b % m == 0))
val lemma_mul_mod_prime_zero: #m:prime -> a:nat_mod m -> b:nat_mod m -> Lemma (a * b % m == 0 <==> (a % m == 0 \/ b % m == 0))
let lemma_mul_mod_prime_zero #m a b = Classical.move_requires_3 Euclid.euclid_prime m a b; Classical.move_requires_3 lemma_mul_mod_zero2 m a b
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 53, "end_line": 415, "start_col": 0, "start_line": 413 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; } let lemma_div_mod_prime_one #m a = lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m let lemma_div_mod_prime_cancel #m a b c = calc (==) { mul_mod (mul_mod a c) (inv_mod (mul_mod c b)); (==) { lemma_inv_mod_both c b } mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b)); (==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) } mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b); (==) { lemma_mul_mod_assoc a c (inv_mod c) } mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b); (==) { lemma_div_mod_prime c } mul_mod (mul_mod a 1) (inv_mod b); (==) { Math.Lemmas.small_mod a m } mul_mod a (inv_mod b); } let lemma_div_mod_prime_to_one_denominator #m a b c d = calc (==) { mul_mod (div_mod a c) (div_mod b d); (==) { } mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d)); (==) { lemma_mul_mod_comm #m b (inv_mod d); lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b } mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b; (==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) } mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b; (==) { lemma_inv_mod_both c d } mul_mod (mul_mod a (inv_mod (mul_mod c d))) b; (==) { lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b; lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b; lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) } mul_mod (mul_mod a b) (inv_mod (mul_mod c d)); } val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (div_mod a b = c ==> a = mul_mod c b) let lemma_div_mod_eq_mul_mod1 #m a b c = if div_mod a b = c then begin assert (mul_mod (div_mod a b) b = mul_mod c b); calc (==) { mul_mod (div_mod a b) b; (==) { lemma_div_mod_prime_one b } mul_mod (div_mod a b) (div_mod b 1); (==) { lemma_div_mod_prime_to_one_denominator a b b 1 } div_mod (mul_mod a b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel a 1 b } div_mod a 1; (==) { lemma_div_mod_prime_one a } a; } end else () val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (a = mul_mod c b ==> div_mod a b = c) let lemma_div_mod_eq_mul_mod2 #m a b c = if a = mul_mod c b then begin assert (div_mod a b == div_mod (mul_mod c b) b); calc (==) { div_mod (mul_mod c b) b; (==) { Math.Lemmas.small_mod b m } div_mod (mul_mod c b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel c 1 b } div_mod c 1; (==) { lemma_div_mod_prime_one c } c; } end else () let lemma_div_mod_eq_mul_mod #m a b c = lemma_div_mod_eq_mul_mod1 a b c; lemma_div_mod_eq_mul_mod2 a b c val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma (requires x % n == 0 \/ y % n == 0) (ensures x * y % n == 0) let lemma_mul_mod_zero2 n x y = if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else Math.Lemmas.lemma_mod_mul_distr_r x y n
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "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": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures a * b % m == 0 <==> a % m == 0 \/ b % m == 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.NatMod.prime", "Lib.NatMod.nat_mod", "FStar.Classical.move_requires_3", "Prims.pos", "Prims.int", "Prims.l_or", "Prims.eq2", "Prims.op_Modulus", "FStar.Mul.op_Star", "Lib.NatMod.lemma_mul_mod_zero2", "Prims.unit", "FStar.Math.Euclid.is_prime", "Prims.b2t", "Prims.op_Equality", "FStar.Math.Euclid.euclid_prime" ]
[]
false
false
true
false
false
let lemma_mul_mod_prime_zero #m a b =
Classical.move_requires_3 Euclid.euclid_prime m a b; Classical.move_requires_3 lemma_mul_mod_zero2 m a b
false
Lib.NatMod.fst
Lib.NatMod.lemma_div_mod_eq_mul_mod2
val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (a = mul_mod c b ==> div_mod a b = c)
val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (a = mul_mod c b ==> div_mod a b = c)
let lemma_div_mod_eq_mul_mod2 #m a b c = if a = mul_mod c b then begin assert (div_mod a b == div_mod (mul_mod c b) b); calc (==) { div_mod (mul_mod c b) b; (==) { Math.Lemmas.small_mod b m } div_mod (mul_mod c b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel c 1 b } div_mod c 1; (==) { lemma_div_mod_prime_one c } c; } end else ()
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 9, "end_line": 394, "start_col": 0, "start_line": 382 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; } let lemma_div_mod_prime_one #m a = lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m let lemma_div_mod_prime_cancel #m a b c = calc (==) { mul_mod (mul_mod a c) (inv_mod (mul_mod c b)); (==) { lemma_inv_mod_both c b } mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b)); (==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) } mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b); (==) { lemma_mul_mod_assoc a c (inv_mod c) } mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b); (==) { lemma_div_mod_prime c } mul_mod (mul_mod a 1) (inv_mod b); (==) { Math.Lemmas.small_mod a m } mul_mod a (inv_mod b); } let lemma_div_mod_prime_to_one_denominator #m a b c d = calc (==) { mul_mod (div_mod a c) (div_mod b d); (==) { } mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d)); (==) { lemma_mul_mod_comm #m b (inv_mod d); lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b } mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b; (==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) } mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b; (==) { lemma_inv_mod_both c d } mul_mod (mul_mod a (inv_mod (mul_mod c d))) b; (==) { lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b; lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b; lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) } mul_mod (mul_mod a b) (inv_mod (mul_mod c d)); } val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (div_mod a b = c ==> a = mul_mod c b) let lemma_div_mod_eq_mul_mod1 #m a b c = if div_mod a b = c then begin assert (mul_mod (div_mod a b) b = mul_mod c b); calc (==) { mul_mod (div_mod a b) b; (==) { lemma_div_mod_prime_one b } mul_mod (div_mod a b) (div_mod b 1); (==) { lemma_div_mod_prime_to_one_denominator a b b 1 } div_mod (mul_mod a b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel a 1 b } div_mod a 1; (==) { lemma_div_mod_prime_one a } a; } end else () val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (a = mul_mod c b ==> div_mod a b = c)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "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": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m {b <> 0} -> c: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures a = Lib.NatMod.mul_mod c b ==> Lib.NatMod.div_mod a b = c)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.NatMod.prime", "Lib.NatMod.nat_mod", "Prims.b2t", "Prims.op_disEquality", "Prims.int", "Prims.op_Equality", "Lib.NatMod.mul_mod", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.NatMod.div_mod", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "FStar.Math.Lemmas.small_mod", "Prims.squash", "Lib.NatMod.lemma_div_mod_prime_cancel", "Lib.NatMod.lemma_div_mod_prime_one", "Prims._assert", "Prims.bool" ]
[]
false
false
true
false
false
let lemma_div_mod_eq_mul_mod2 #m a b c =
if a = mul_mod c b then (assert (div_mod a b == div_mod (mul_mod c b) b); calc ( == ) { div_mod (mul_mod c b) b; ( == ) { Math.Lemmas.small_mod b m } div_mod (mul_mod c b) (mul_mod b 1); ( == ) { lemma_div_mod_prime_cancel c 1 b } div_mod c 1; ( == ) { lemma_div_mod_prime_one c } c; })
false
FStar.UInt8.fsti
FStar.UInt8.op_Percent_Hat
val op_Percent_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t{FStar.UInt8.v b <> 0} -> Prims.Pure FStar.UInt8.t
let op_Percent_Hat = rem
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 326, "start_col": 7, "start_line": 326 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t{FStar.UInt8.v b <> 0} -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.rem" ]
[]
false
false
false
false
false
let op_Percent_Hat =
rem
false
Lib.NatMod.fst
Lib.NatMod.lemma_div_mod_prime_to_one_denominator
val lemma_div_mod_prime_to_one_denominator: #m:pos{1 < m} -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m{c <> 0} -> d:nat_mod m{d <> 0} -> Lemma (mul_mod (div_mod a c) (div_mod b d) == div_mod (mul_mod a b) (mul_mod c d))
val lemma_div_mod_prime_to_one_denominator: #m:pos{1 < m} -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m{c <> 0} -> d:nat_mod m{d <> 0} -> Lemma (mul_mod (div_mod a c) (div_mod b d) == div_mod (mul_mod a b) (mul_mod c d))
let lemma_div_mod_prime_to_one_denominator #m a b c d = calc (==) { mul_mod (div_mod a c) (div_mod b d); (==) { } mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d)); (==) { lemma_mul_mod_comm #m b (inv_mod d); lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b } mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b; (==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) } mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b; (==) { lemma_inv_mod_both c d } mul_mod (mul_mod a (inv_mod (mul_mod c d))) b; (==) { lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b; lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b; lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) } mul_mod (mul_mod a b) (inv_mod (mul_mod c d)); }
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 356, "start_col": 0, "start_line": 338 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; } let lemma_div_mod_prime_one #m a = lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m let lemma_div_mod_prime_cancel #m a b c = calc (==) { mul_mod (mul_mod a c) (inv_mod (mul_mod c b)); (==) { lemma_inv_mod_both c b } mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b)); (==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) } mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b); (==) { lemma_mul_mod_assoc a c (inv_mod c) } mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b); (==) { lemma_div_mod_prime c } mul_mod (mul_mod a 1) (inv_mod b); (==) { Math.Lemmas.small_mod a m } mul_mod a (inv_mod b); }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "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": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m {c <> 0} -> d: Lib.NatMod.nat_mod m {d <> 0} -> FStar.Pervasives.Lemma (ensures Lib.NatMod.mul_mod (Lib.NatMod.div_mod a c) (Lib.NatMod.div_mod b d) == Lib.NatMod.div_mod (Lib.NatMod.mul_mod a b) (Lib.NatMod.mul_mod c d))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.b2t", "Prims.op_LessThan", "Lib.NatMod.nat_mod", "Prims.op_disEquality", "Prims.int", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.NatMod.mul_mod", "Lib.NatMod.div_mod", "Lib.NatMod.inv_mod", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Prims.squash", "Lib.NatMod.lemma_mul_mod_assoc", "Lib.NatMod.lemma_mul_mod_comm", "Lib.NatMod.lemma_inv_mod_both" ]
[]
false
false
true
false
false
let lemma_div_mod_prime_to_one_denominator #m a b c d =
calc ( == ) { mul_mod (div_mod a c) (div_mod b d); ( == ) { () } mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d)); ( == ) { (lemma_mul_mod_comm #m b (inv_mod d); lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b) } mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b; ( == ) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) } mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b; ( == ) { lemma_inv_mod_both c d } mul_mod (mul_mod a (inv_mod (mul_mod c d))) b; ( == ) { (lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b; lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b; lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d))) } mul_mod (mul_mod a b) (inv_mod (mul_mod c d)); }
false
FStar.UInt8.fsti
FStar.UInt8.op_Less_Less_Hat
val op_Less_Less_Hat : a: FStar.UInt8.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt8.t
let op_Less_Less_Hat = shift_left
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 40, "end_line": 330, "start_col": 7, "start_line": 330 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.shift_left" ]
[]
false
false
false
false
false
let op_Less_Less_Hat =
shift_left
false
Lib.NatMod.fst
Lib.NatMod.lemma_div_mod_prime_is_zero2
val lemma_div_mod_prime_is_zero2: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma (requires div_mod a b = 0) (ensures a = 0 || b = 0)
val lemma_div_mod_prime_is_zero2: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma (requires div_mod a b = 0) (ensures a = 0 || b = 0)
let lemma_div_mod_prime_is_zero2 #m a b = lemma_mul_mod_prime_zero a (inv_mod b); assert (a = 0 || inv_mod b = 0); lemma_pow_mod_prime_zero #m b (m - 2)
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 458, "start_col": 0, "start_line": 455 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; } let lemma_div_mod_prime_one #m a = lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m let lemma_div_mod_prime_cancel #m a b c = calc (==) { mul_mod (mul_mod a c) (inv_mod (mul_mod c b)); (==) { lemma_inv_mod_both c b } mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b)); (==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) } mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b); (==) { lemma_mul_mod_assoc a c (inv_mod c) } mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b); (==) { lemma_div_mod_prime c } mul_mod (mul_mod a 1) (inv_mod b); (==) { Math.Lemmas.small_mod a m } mul_mod a (inv_mod b); } let lemma_div_mod_prime_to_one_denominator #m a b c d = calc (==) { mul_mod (div_mod a c) (div_mod b d); (==) { } mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d)); (==) { lemma_mul_mod_comm #m b (inv_mod d); lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b } mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b; (==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) } mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b; (==) { lemma_inv_mod_both c d } mul_mod (mul_mod a (inv_mod (mul_mod c d))) b; (==) { lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b; lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b; lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) } mul_mod (mul_mod a b) (inv_mod (mul_mod c d)); } val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (div_mod a b = c ==> a = mul_mod c b) let lemma_div_mod_eq_mul_mod1 #m a b c = if div_mod a b = c then begin assert (mul_mod (div_mod a b) b = mul_mod c b); calc (==) { mul_mod (div_mod a b) b; (==) { lemma_div_mod_prime_one b } mul_mod (div_mod a b) (div_mod b 1); (==) { lemma_div_mod_prime_to_one_denominator a b b 1 } div_mod (mul_mod a b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel a 1 b } div_mod a 1; (==) { lemma_div_mod_prime_one a } a; } end else () val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (a = mul_mod c b ==> div_mod a b = c) let lemma_div_mod_eq_mul_mod2 #m a b c = if a = mul_mod c b then begin assert (div_mod a b == div_mod (mul_mod c b) b); calc (==) { div_mod (mul_mod c b) b; (==) { Math.Lemmas.small_mod b m } div_mod (mul_mod c b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel c 1 b } div_mod c 1; (==) { lemma_div_mod_prime_one c } c; } end else () let lemma_div_mod_eq_mul_mod #m a b c = lemma_div_mod_eq_mul_mod1 a b c; lemma_div_mod_eq_mul_mod2 a b c val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma (requires x % n == 0 \/ y % n == 0) (ensures x * y % n == 0) let lemma_mul_mod_zero2 n x y = if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else Math.Lemmas.lemma_mod_mul_distr_r x y n let lemma_mul_mod_prime_zero #m a b = Classical.move_requires_3 Euclid.euclid_prime m a b; Classical.move_requires_3 lemma_mul_mod_zero2 m a b val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma (requires pow a b % m = 0) (ensures a = 0) #push-options "--z3rlimit 150" let rec lemma_pow_mod_prime_zero_ #m a b = if b = 1 then lemma_pow1 a else begin let r1 = pow a (b - 1) % m in lemma_pow_unfold a b; assert (a * pow a (b - 1) % m = 0); Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) m; lemma_mul_mod_prime_zero #m a r1; //assert (a = 0 \/ r1 = 0); if a = 0 then () else lemma_pow_mod_prime_zero_ #m a (b - 1) end #pop-options let lemma_pow_mod_prime_zero #m a b = lemma_pow_mod #m a b; Classical.move_requires_2 lemma_pow_mod_prime_zero_ a b; Classical.move_requires lemma_pow_zero b val lemma_div_mod_is_zero1: #m:pos{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma (requires a = 0 || b = 0) (ensures div_mod a b = 0) let lemma_div_mod_is_zero1 #m a b = if a = 0 then () else begin lemma_pow_mod #m b (m - 2); lemma_pow_zero (m - 2) end val lemma_div_mod_prime_is_zero2: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma (requires div_mod a b = 0) (ensures a = 0 || b = 0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "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": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (requires Lib.NatMod.div_mod a b = 0) (ensures a = 0 || b = 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.NatMod.prime", "Prims.b2t", "Prims.op_LessThan", "Lib.NatMod.nat_mod", "Lib.NatMod.lemma_pow_mod_prime_zero", "Prims.op_Subtraction", "Prims.unit", "Prims._assert", "Prims.op_BarBar", "Prims.op_Equality", "Prims.int", "Lib.NatMod.inv_mod", "Lib.NatMod.lemma_mul_mod_prime_zero" ]
[]
true
false
true
false
false
let lemma_div_mod_prime_is_zero2 #m a b =
lemma_mul_mod_prime_zero a (inv_mod b); assert (a = 0 || inv_mod b = 0); lemma_pow_mod_prime_zero #m b (m - 2)
false
FStar.UInt8.fsti
FStar.UInt8.op_Star_Question_Hat
val op_Star_Question_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
let op_Star_Question_Hat = mul_underspec
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 323, "start_col": 7, "start_line": 323 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.mul_underspec" ]
[]
false
false
false
false
false
let op_Star_Question_Hat =
mul_underspec
false
FStar.UInt8.fsti
FStar.UInt8.n_minus_one
val n_minus_one : FStar.UInt32.t
let n_minus_one = UInt32.uint_to_t (n - 1)
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 42, "end_line": 244, "start_col": 0, "start_line": 244 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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
FStar.UInt32.t
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.uint_to_t", "Prims.op_Subtraction", "FStar.UInt8.n" ]
[]
false
false
false
true
false
let n_minus_one =
UInt32.uint_to_t (n - 1)
false
FStar.UInt8.fsti
FStar.UInt8.op_Amp_Hat
val op_Amp_Hat : x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
let op_Amp_Hat = logand
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 328, "start_col": 7, "start_line": 328 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.logand" ]
[]
false
false
false
false
false
let op_Amp_Hat =
logand
false
Lib.NatMod.fst
Lib.NatMod.lemma_inv_mod_both
val lemma_inv_mod_both: #m:pos{1 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma (inv_mod (mul_mod a b) == mul_mod (inv_mod a) (inv_mod b))
val lemma_inv_mod_both: #m:pos{1 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma (inv_mod (mul_mod a b) == mul_mod (inv_mod a) (inv_mod b))
let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); }
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 285, "start_col": 0, "start_line": 267 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "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": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.inv_mod (Lib.NatMod.mul_mod a b) == Lib.NatMod.mul_mod (Lib.NatMod.inv_mod a) (Lib.NatMod.inv_mod b))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.b2t", "Prims.op_LessThan", "Lib.NatMod.nat_mod", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.NatMod.mul_mod", "Lib.NatMod.inv_mod", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "Prims.op_Modulus", "Lib.NatMod.pow", "Prims.op_Subtraction", "FStar.Mul.op_Star", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.NatMod.lemma_pow_mod", "Prims.squash", "FStar.Math.Lemmas.lemma_mod_mul_distr_l", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "Lib.NatMod.lemma_pow_mul_base", "Lib.NatMod.lemma_pow_mod_base", "Prims.int" ]
[]
false
false
true
false
false
let lemma_inv_mod_both #m a b =
let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc ( == ) { mul_mod (inv_mod a) (inv_mod b); ( == ) { (lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2)) } (p1 % m) * (p2 % m) % m; ( == ) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; ( == ) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; ( == ) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; ( == ) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; ( == ) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); }
false
Lib.NatMod.fst
Lib.NatMod.lemma_div_mod_eq_mul_mod1
val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (div_mod a b = c ==> a = mul_mod c b)
val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (div_mod a b = c ==> a = mul_mod c b)
let lemma_div_mod_eq_mul_mod1 #m a b c = if div_mod a b = c then begin assert (mul_mod (div_mod a b) b = mul_mod c b); calc (==) { mul_mod (div_mod a b) b; (==) { lemma_div_mod_prime_one b } mul_mod (div_mod a b) (div_mod b 1); (==) { lemma_div_mod_prime_to_one_denominator a b b 1 } div_mod (mul_mod a b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel a 1 b } div_mod a 1; (==) { lemma_div_mod_prime_one a } a; } end else ()
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 9, "end_line": 376, "start_col": 0, "start_line": 362 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; } let lemma_div_mod_prime_one #m a = lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m let lemma_div_mod_prime_cancel #m a b c = calc (==) { mul_mod (mul_mod a c) (inv_mod (mul_mod c b)); (==) { lemma_inv_mod_both c b } mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b)); (==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) } mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b); (==) { lemma_mul_mod_assoc a c (inv_mod c) } mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b); (==) { lemma_div_mod_prime c } mul_mod (mul_mod a 1) (inv_mod b); (==) { Math.Lemmas.small_mod a m } mul_mod a (inv_mod b); } let lemma_div_mod_prime_to_one_denominator #m a b c d = calc (==) { mul_mod (div_mod a c) (div_mod b d); (==) { } mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d)); (==) { lemma_mul_mod_comm #m b (inv_mod d); lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b } mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b; (==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) } mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b; (==) { lemma_inv_mod_both c d } mul_mod (mul_mod a (inv_mod (mul_mod c d))) b; (==) { lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b; lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b; lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) } mul_mod (mul_mod a b) (inv_mod (mul_mod c d)); } val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (div_mod a b = c ==> a = mul_mod c b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "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": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m {b <> 0} -> c: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.div_mod a b = c ==> a = Lib.NatMod.mul_mod c b)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.NatMod.prime", "Lib.NatMod.nat_mod", "Prims.b2t", "Prims.op_disEquality", "Prims.int", "Prims.op_Equality", "Lib.NatMod.div_mod", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.NatMod.mul_mod", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.NatMod.lemma_div_mod_prime_one", "Prims.squash", "Lib.NatMod.lemma_div_mod_prime_to_one_denominator", "Lib.NatMod.lemma_div_mod_prime_cancel", "Prims._assert", "Prims.bool" ]
[]
false
false
true
false
false
let lemma_div_mod_eq_mul_mod1 #m a b c =
if div_mod a b = c then (assert (mul_mod (div_mod a b) b = mul_mod c b); calc ( == ) { mul_mod (div_mod a b) b; ( == ) { lemma_div_mod_prime_one b } mul_mod (div_mod a b) (div_mod b 1); ( == ) { lemma_div_mod_prime_to_one_denominator a b b 1 } div_mod (mul_mod a b) (mul_mod b 1); ( == ) { lemma_div_mod_prime_cancel a 1 b } div_mod a 1; ( == ) { lemma_div_mod_prime_one a } a; })
false
FStar.UInt8.fsti
FStar.UInt8.op_Hat_Hat
val op_Hat_Hat : x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
let op_Hat_Hat = logxor
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 327, "start_col": 7, "start_line": 327 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.logxor" ]
[]
false
false
false
false
false
let op_Hat_Hat =
logxor
false
FStar.UInt8.fsti
FStar.UInt8.op_Less_Hat
val op_Less_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
let op_Less_Hat = lt
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 335, "start_col": 7, "start_line": 335 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand unfold let op_Bar_Hat = logor unfold let op_Less_Less_Hat = shift_left unfold let op_Greater_Greater_Hat = shift_right unfold let op_Equals_Hat = eq unfold let op_Greater_Hat = gt
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.lt" ]
[]
false
false
false
true
false
let op_Less_Hat =
lt
false
FStar.UInt8.fsti
FStar.UInt8.op_Bar_Hat
val op_Bar_Hat : x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
let op_Bar_Hat = logor
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 329, "start_col": 7, "start_line": 329 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.logor" ]
[]
false
false
false
false
false
let op_Bar_Hat =
logor
false
FStar.UInt8.fsti
FStar.UInt8.op_Greater_Greater_Hat
val op_Greater_Greater_Hat : a: FStar.UInt8.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt8.t
let op_Greater_Greater_Hat = shift_right
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 47, "end_line": 331, "start_col": 7, "start_line": 331 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand unfold let op_Bar_Hat = logor
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.shift_right" ]
[]
false
false
false
false
false
let op_Greater_Greater_Hat =
shift_right
false
FStar.UInt8.fsti
FStar.UInt8.op_Greater_Equals_Hat
val op_Greater_Equals_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
let op_Greater_Equals_Hat = gte
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 38, "end_line": 334, "start_col": 7, "start_line": 334 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand unfold let op_Bar_Hat = logor unfold let op_Less_Less_Hat = shift_left unfold let op_Greater_Greater_Hat = shift_right unfold let op_Equals_Hat = eq
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.gte" ]
[]
false
false
false
true
false
let op_Greater_Equals_Hat =
gte
false
Lib.NatMod.fst
Lib.NatMod.lemma_div_mod_prime_cancel
val lemma_div_mod_prime_cancel: #m:prime -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m{c <> 0} -> Lemma (div_mod (mul_mod a c) (mul_mod c b) == div_mod a b)
val lemma_div_mod_prime_cancel: #m:prime -> a:nat_mod m -> b:nat_mod m -> c:nat_mod m{c <> 0} -> Lemma (div_mod (mul_mod a c) (mul_mod c b) == div_mod a b)
let lemma_div_mod_prime_cancel #m a b c = calc (==) { mul_mod (mul_mod a c) (inv_mod (mul_mod c b)); (==) { lemma_inv_mod_both c b } mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b)); (==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) } mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b); (==) { lemma_mul_mod_assoc a c (inv_mod c) } mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b); (==) { lemma_div_mod_prime c } mul_mod (mul_mod a 1) (inv_mod b); (==) { Math.Lemmas.small_mod a m } mul_mod a (inv_mod b); }
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 335, "start_col": 0, "start_line": 322 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; } let lemma_div_mod_prime_one #m a = lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "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": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> c: Lib.NatMod.nat_mod m {c <> 0} -> FStar.Pervasives.Lemma (ensures Lib.NatMod.div_mod (Lib.NatMod.mul_mod a c) (Lib.NatMod.mul_mod c b) == Lib.NatMod.div_mod a b )
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.NatMod.prime", "Lib.NatMod.nat_mod", "Prims.b2t", "Prims.op_disEquality", "Prims.int", "FStar.Calc.calc_finish", "Prims.eq2", "Lib.NatMod.mul_mod", "Lib.NatMod.inv_mod", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "Prims.unit", "FStar.Calc.calc_step", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.NatMod.lemma_inv_mod_both", "Prims.squash", "Lib.NatMod.lemma_mul_mod_assoc", "Lib.NatMod.lemma_div_mod_prime", "FStar.Math.Lemmas.small_mod" ]
[]
false
false
true
false
false
let lemma_div_mod_prime_cancel #m a b c =
calc ( == ) { mul_mod (mul_mod a c) (inv_mod (mul_mod c b)); ( == ) { lemma_inv_mod_both c b } mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b)); ( == ) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) } mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b); ( == ) { lemma_mul_mod_assoc a c (inv_mod c) } mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b); ( == ) { lemma_div_mod_prime c } mul_mod (mul_mod a 1) (inv_mod b); ( == ) { Math.Lemmas.small_mod a m } mul_mod a (inv_mod b); }
false
FStar.UInt8.fsti
FStar.UInt8.op_Greater_Hat
val op_Greater_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
let op_Greater_Hat = gt
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 30, "end_line": 333, "start_col": 7, "start_line": 333 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand unfold let op_Bar_Hat = logor unfold let op_Less_Less_Hat = shift_left unfold let op_Greater_Greater_Hat = shift_right
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.gt" ]
[]
false
false
false
true
false
let op_Greater_Hat =
gt
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_mod_
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b)
val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b)
let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 5, "end_line": 184, "start_col": 0, "start_line": 145 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "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": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: Prims.pos{1 < n} -> a: Lib.NatMod.nat_mod n -> b: Prims.nat -> FStar.Pervasives.Lemma (ensures Lib.NatMod.pow_mod a b == Lib.NatMod.pow a b % n) (decreases b)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "Prims.pos", "Prims.b2t", "Prims.op_LessThan", "Lib.NatMod.nat_mod", "Prims.nat", "Prims.op_Equality", "Prims.int", "Lib.NatMod.lemma_pow_mod0", "Prims.unit", "Lib.NatMod.lemma_pow0", "Prims.bool", "Prims.op_Modulus", "Prims._assert", "Prims.eq2", "Lib.NatMod.pow_mod", "Lib.NatMod.pow", "FStar.Calc.calc_finish", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "FStar.Mul.op_Star", "Prims.op_Division", "Lib.NatMod.mul_mod", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Lib.NatMod.lemma_pow_mod_unfold0", "Prims.squash", "Lib.NatMod.lemma_pow_mod_", "Lib.NatMod.lemma_pow_mod_base", "Lib.NatMod.lemma_pow_double", "Prims.op_Addition", "Lib.NatMod.lemma_pow_mod_unfold1", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "Lib.NatMod.lemma_pow1", "Lib.NatMod.lemma_pow_add", "FStar.Math.Lemmas.euclidean_division_definition" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_pow_mod_ n a b =
if b = 0 then (lemma_pow0 a; lemma_pow_mod0 a) else if b % 2 = 0 then (calc ( == ) { pow_mod #n a b; ( == ) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); ( == ) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; ( == ) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; ( == ) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n)) else (calc ( == ) { pow_mod #n a b; ( == ) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); ( == ) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); ( == ) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); ( == ) { lemma_pow_double a (b / 2) } mul_mod a (pow a ((b / 2) * 2) % n); ( == ) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a ((b / 2) * 2)) n } a * pow a ((b / 2) * 2) % n; ( == ) { lemma_pow1 a } pow a 1 * pow a ((b / 2) * 2) % n; ( == ) { lemma_pow_add a 1 ((b / 2) * 2) } pow a ((b / 2) * 2 + 1) % n; ( == ) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n))
false
FStar.UInt8.fsti
FStar.UInt8.op_Equals_Hat
val op_Equals_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
let op_Equals_Hat = eq
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 29, "end_line": 332, "start_col": 7, "start_line": 332 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand unfold let op_Bar_Hat = logor unfold let op_Less_Less_Hat = shift_left
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.eq" ]
[]
false
false
false
true
false
let op_Equals_Hat =
eq
false
Lib.NatMod.fst
Lib.NatMod.lemma_div_mod_is_zero1
val lemma_div_mod_is_zero1: #m:pos{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma (requires a = 0 || b = 0) (ensures div_mod a b = 0)
val lemma_div_mod_is_zero1: #m:pos{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma (requires a = 0 || b = 0) (ensures div_mod a b = 0)
let lemma_div_mod_is_zero1 #m a b = if a = 0 then () else begin lemma_pow_mod #m b (m - 2); lemma_pow_zero (m - 2) end
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 30, "end_line": 449, "start_col": 0, "start_line": 445 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; } let lemma_div_mod_prime_one #m a = lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m let lemma_div_mod_prime_cancel #m a b c = calc (==) { mul_mod (mul_mod a c) (inv_mod (mul_mod c b)); (==) { lemma_inv_mod_both c b } mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b)); (==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) } mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b); (==) { lemma_mul_mod_assoc a c (inv_mod c) } mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b); (==) { lemma_div_mod_prime c } mul_mod (mul_mod a 1) (inv_mod b); (==) { Math.Lemmas.small_mod a m } mul_mod a (inv_mod b); } let lemma_div_mod_prime_to_one_denominator #m a b c d = calc (==) { mul_mod (div_mod a c) (div_mod b d); (==) { } mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d)); (==) { lemma_mul_mod_comm #m b (inv_mod d); lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b } mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b; (==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) } mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b; (==) { lemma_inv_mod_both c d } mul_mod (mul_mod a (inv_mod (mul_mod c d))) b; (==) { lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b; lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b; lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) } mul_mod (mul_mod a b) (inv_mod (mul_mod c d)); } val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (div_mod a b = c ==> a = mul_mod c b) let lemma_div_mod_eq_mul_mod1 #m a b c = if div_mod a b = c then begin assert (mul_mod (div_mod a b) b = mul_mod c b); calc (==) { mul_mod (div_mod a b) b; (==) { lemma_div_mod_prime_one b } mul_mod (div_mod a b) (div_mod b 1); (==) { lemma_div_mod_prime_to_one_denominator a b b 1 } div_mod (mul_mod a b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel a 1 b } div_mod a 1; (==) { lemma_div_mod_prime_one a } a; } end else () val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (a = mul_mod c b ==> div_mod a b = c) let lemma_div_mod_eq_mul_mod2 #m a b c = if a = mul_mod c b then begin assert (div_mod a b == div_mod (mul_mod c b) b); calc (==) { div_mod (mul_mod c b) b; (==) { Math.Lemmas.small_mod b m } div_mod (mul_mod c b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel c 1 b } div_mod c 1; (==) { lemma_div_mod_prime_one c } c; } end else () let lemma_div_mod_eq_mul_mod #m a b c = lemma_div_mod_eq_mul_mod1 a b c; lemma_div_mod_eq_mul_mod2 a b c val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma (requires x % n == 0 \/ y % n == 0) (ensures x * y % n == 0) let lemma_mul_mod_zero2 n x y = if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else Math.Lemmas.lemma_mod_mul_distr_r x y n let lemma_mul_mod_prime_zero #m a b = Classical.move_requires_3 Euclid.euclid_prime m a b; Classical.move_requires_3 lemma_mul_mod_zero2 m a b val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma (requires pow a b % m = 0) (ensures a = 0) #push-options "--z3rlimit 150" let rec lemma_pow_mod_prime_zero_ #m a b = if b = 1 then lemma_pow1 a else begin let r1 = pow a (b - 1) % m in lemma_pow_unfold a b; assert (a * pow a (b - 1) % m = 0); Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) m; lemma_mul_mod_prime_zero #m a r1; //assert (a = 0 \/ r1 = 0); if a = 0 then () else lemma_pow_mod_prime_zero_ #m a (b - 1) end #pop-options let lemma_pow_mod_prime_zero #m a b = lemma_pow_mod #m a b; Classical.move_requires_2 lemma_pow_mod_prime_zero_ a b; Classical.move_requires lemma_pow_zero b val lemma_div_mod_is_zero1: #m:pos{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma (requires a = 0 || b = 0) (ensures div_mod a b = 0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "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": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (requires a = 0 || b = 0) (ensures Lib.NatMod.div_mod a b = 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.pos", "Prims.b2t", "Prims.op_LessThan", "Lib.NatMod.nat_mod", "Prims.op_Equality", "Prims.int", "Prims.bool", "Lib.NatMod.lemma_pow_zero", "Prims.op_Subtraction", "Prims.unit", "Lib.NatMod.lemma_pow_mod" ]
[]
false
false
true
false
false
let lemma_div_mod_is_zero1 #m a b =
if a = 0 then () else (lemma_pow_mod #m b (m - 2); lemma_pow_zero (m - 2))
false
FStar.UInt8.fsti
FStar.UInt8.minus
val minus : a: FStar.UInt8.t -> FStar.UInt8.t
let minus (a:t) = add_mod (lognot a) (uint_to_t 1)
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 50, "end_line": 239, "start_col": 0, "start_line": 239 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> FStar.UInt8.t
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.t", "FStar.UInt8.add_mod", "FStar.UInt8.lognot", "FStar.UInt8.uint_to_t" ]
[]
false
false
false
true
false
let minus (a: t) =
add_mod (lognot a) (uint_to_t 1)
false
FStar.UInt8.fsti
FStar.UInt8.op_Less_Equals_Hat
val op_Less_Equals_Hat : a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
let op_Less_Equals_Hat = lte
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 35, "end_line": 336, "start_col": 7, "start_line": 336 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *) [@ CNoInline ] let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c #reset-options (*** Infix notations *) unfold let op_Plus_Hat = add unfold let op_Plus_Question_Hat = add_underspec unfold let op_Plus_Percent_Hat = add_mod unfold let op_Subtraction_Hat = sub unfold let op_Subtraction_Question_Hat = sub_underspec unfold let op_Subtraction_Percent_Hat = sub_mod unfold let op_Star_Hat = mul unfold let op_Star_Question_Hat = mul_underspec unfold let op_Star_Percent_Hat = mul_mod unfold let op_Slash_Hat = div unfold let op_Percent_Hat = rem unfold let op_Hat_Hat = logxor unfold let op_Amp_Hat = logand unfold let op_Bar_Hat = logor unfold let op_Less_Less_Hat = shift_left unfold let op_Greater_Greater_Hat = shift_right unfold let op_Equals_Hat = eq unfold let op_Greater_Hat = gt unfold let op_Greater_Equals_Hat = gte
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt8.lte" ]
[]
false
false
false
true
false
let op_Less_Equals_Hat =
lte
false
Lib.NatMod.fst
Lib.NatMod.lemma_div_mod_prime_is_zero
val lemma_div_mod_prime_is_zero: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma ((div_mod a b = 0) <==> (a = 0 || b = 0))
val lemma_div_mod_prime_is_zero: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma ((div_mod a b = 0) <==> (a = 0 || b = 0))
let lemma_div_mod_prime_is_zero #m a b = Classical.move_requires_2 lemma_div_mod_is_zero1 a b; Classical.move_requires_2 lemma_div_mod_prime_is_zero2 a b
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 60, "end_line": 463, "start_col": 0, "start_line": 461 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; } let lemma_div_mod_prime_one #m a = lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m let lemma_div_mod_prime_cancel #m a b c = calc (==) { mul_mod (mul_mod a c) (inv_mod (mul_mod c b)); (==) { lemma_inv_mod_both c b } mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b)); (==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) } mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b); (==) { lemma_mul_mod_assoc a c (inv_mod c) } mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b); (==) { lemma_div_mod_prime c } mul_mod (mul_mod a 1) (inv_mod b); (==) { Math.Lemmas.small_mod a m } mul_mod a (inv_mod b); } let lemma_div_mod_prime_to_one_denominator #m a b c d = calc (==) { mul_mod (div_mod a c) (div_mod b d); (==) { } mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d)); (==) { lemma_mul_mod_comm #m b (inv_mod d); lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b } mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b; (==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) } mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b; (==) { lemma_inv_mod_both c d } mul_mod (mul_mod a (inv_mod (mul_mod c d))) b; (==) { lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b; lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b; lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) } mul_mod (mul_mod a b) (inv_mod (mul_mod c d)); } val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (div_mod a b = c ==> a = mul_mod c b) let lemma_div_mod_eq_mul_mod1 #m a b c = if div_mod a b = c then begin assert (mul_mod (div_mod a b) b = mul_mod c b); calc (==) { mul_mod (div_mod a b) b; (==) { lemma_div_mod_prime_one b } mul_mod (div_mod a b) (div_mod b 1); (==) { lemma_div_mod_prime_to_one_denominator a b b 1 } div_mod (mul_mod a b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel a 1 b } div_mod a 1; (==) { lemma_div_mod_prime_one a } a; } end else () val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (a = mul_mod c b ==> div_mod a b = c) let lemma_div_mod_eq_mul_mod2 #m a b c = if a = mul_mod c b then begin assert (div_mod a b == div_mod (mul_mod c b) b); calc (==) { div_mod (mul_mod c b) b; (==) { Math.Lemmas.small_mod b m } div_mod (mul_mod c b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel c 1 b } div_mod c 1; (==) { lemma_div_mod_prime_one c } c; } end else () let lemma_div_mod_eq_mul_mod #m a b c = lemma_div_mod_eq_mul_mod1 a b c; lemma_div_mod_eq_mul_mod2 a b c val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma (requires x % n == 0 \/ y % n == 0) (ensures x * y % n == 0) let lemma_mul_mod_zero2 n x y = if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else Math.Lemmas.lemma_mod_mul_distr_r x y n let lemma_mul_mod_prime_zero #m a b = Classical.move_requires_3 Euclid.euclid_prime m a b; Classical.move_requires_3 lemma_mul_mod_zero2 m a b val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma (requires pow a b % m = 0) (ensures a = 0) #push-options "--z3rlimit 150" let rec lemma_pow_mod_prime_zero_ #m a b = if b = 1 then lemma_pow1 a else begin let r1 = pow a (b - 1) % m in lemma_pow_unfold a b; assert (a * pow a (b - 1) % m = 0); Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) m; lemma_mul_mod_prime_zero #m a r1; //assert (a = 0 \/ r1 = 0); if a = 0 then () else lemma_pow_mod_prime_zero_ #m a (b - 1) end #pop-options let lemma_pow_mod_prime_zero #m a b = lemma_pow_mod #m a b; Classical.move_requires_2 lemma_pow_mod_prime_zero_ a b; Classical.move_requires lemma_pow_zero b val lemma_div_mod_is_zero1: #m:pos{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma (requires a = 0 || b = 0) (ensures div_mod a b = 0) let lemma_div_mod_is_zero1 #m a b = if a = 0 then () else begin lemma_pow_mod #m b (m - 2); lemma_pow_zero (m - 2) end val lemma_div_mod_prime_is_zero2: #m:prime{2 < m} -> a:nat_mod m -> b:nat_mod m -> Lemma (requires div_mod a b = 0) (ensures a = 0 || b = 0) let lemma_div_mod_prime_is_zero2 #m a b = lemma_mul_mod_prime_zero a (inv_mod b); assert (a = 0 || inv_mod b = 0); lemma_pow_mod_prime_zero #m b (m - 2)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "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": 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": 30, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Lib.NatMod.nat_mod m -> FStar.Pervasives.Lemma (ensures Lib.NatMod.div_mod a b = 0 <==> a = 0 || b = 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.NatMod.prime", "Prims.b2t", "Prims.op_LessThan", "Lib.NatMod.nat_mod", "FStar.Classical.move_requires_2", "Prims.op_Equality", "Prims.int", "Lib.NatMod.div_mod", "Prims.op_BarBar", "Lib.NatMod.lemma_div_mod_prime_is_zero2", "Prims.unit", "Lib.NatMod.lemma_div_mod_is_zero1" ]
[]
false
false
true
false
false
let lemma_div_mod_prime_is_zero #m a b =
Classical.move_requires_2 lemma_div_mod_is_zero1 a b; Classical.move_requires_2 lemma_div_mod_prime_is_zero2 a b
false
Lib.NatMod.fst
Lib.NatMod.lemma_pow_mod_prime_zero_
val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma (requires pow a b % m = 0) (ensures a = 0)
val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma (requires pow a b % m = 0) (ensures a = 0)
let rec lemma_pow_mod_prime_zero_ #m a b = if b = 1 then lemma_pow1 a else begin let r1 = pow a (b - 1) % m in lemma_pow_unfold a b; assert (a * pow a (b - 1) % m = 0); Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) m; lemma_mul_mod_prime_zero #m a r1; //assert (a = 0 \/ r1 = 0); if a = 0 then () else lemma_pow_mod_prime_zero_ #m a (b - 1) end
{ "file_name": "lib/Lib.NatMod.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 68, "end_line": 432, "start_col": 0, "start_line": 423 }
module Lib.NatMod module LE = Lib.Exponentiation.Definition #set-options "--z3rlimit 30 --fuel 0 --ifuel 0" #push-options "--fuel 2" let lemma_pow0 a = () let lemma_pow1 a = () let lemma_pow_unfold a b = () #pop-options let rec lemma_pow_gt_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_gt_zero a (b - 1) end let rec lemma_pow_ge_zero a b = if b = 0 then lemma_pow0 a else begin lemma_pow_unfold a b; lemma_pow_ge_zero a (b - 1) end let rec lemma_pow_nat_is_pow a b = let k = mk_nat_comm_monoid in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin lemma_pow_unfold a b; lemma_pow_nat_is_pow a (b - 1); LE.lemma_pow_unfold k a b; () end let lemma_pow_zero b = lemma_pow_unfold 0 b let lemma_pow_one b = let k = mk_nat_comm_monoid in LE.lemma_pow_one k b; lemma_pow_nat_is_pow 1 b let lemma_pow_add x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_add k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow x m; lemma_pow_nat_is_pow x (n + m) let lemma_pow_mul x n m = let k = mk_nat_comm_monoid in LE.lemma_pow_mul k x n m; lemma_pow_nat_is_pow x n; lemma_pow_nat_is_pow (pow x n) m; lemma_pow_nat_is_pow x (n * m) let lemma_pow_double a b = let k = mk_nat_comm_monoid in LE.lemma_pow_double k a b; lemma_pow_nat_is_pow (a * a) b; lemma_pow_nat_is_pow a (b + b) let lemma_pow_mul_base a b n = let k = mk_nat_comm_monoid in LE.lemma_pow_mul_base k a b n; lemma_pow_nat_is_pow a n; lemma_pow_nat_is_pow b n; lemma_pow_nat_is_pow (a * b) n let rec lemma_pow_mod_base a b n = if b = 0 then begin lemma_pow0 a; lemma_pow0 (a % n) end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_mod_base a (b - 1) n } a * (pow (a % n) (b - 1) % n) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow (a % n) (b - 1)) n } a * pow (a % n) (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_l a (pow (a % n) (b - 1)) n } a % n * pow (a % n) (b - 1) % n; (==) { lemma_pow_unfold (a % n) b } pow (a % n) b % n; }; assert (pow a b % n == pow (a % n) b % n) end let lemma_mul_mod_one #m a = () let lemma_mul_mod_assoc #m a b c = calc (==) { (a * b % m) * c % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (a * b) c m } (a * b) * c % m; (==) { Math.Lemmas.paren_mul_right a b c } a * (b * c) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b * c) m } a * (b * c % m) % m; } let lemma_mul_mod_comm #m a b = () let pow_mod #m a b = pow_mod_ #m a b let pow_mod_def #m a b = () #push-options "--fuel 2" val lemma_pow_mod0: #n:pos{1 < n} -> a:nat_mod n -> Lemma (pow_mod #n a 0 == 1) let lemma_pow_mod0 #n a = () val lemma_pow_mod_unfold0: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 0} -> Lemma (pow_mod #n a b == pow_mod (mul_mod a a) (b / 2)) let lemma_pow_mod_unfold0 n a b = () val lemma_pow_mod_unfold1: n:pos{1 < n} -> a:nat_mod n -> b:pos{b % 2 = 1} -> Lemma (pow_mod #n a b == mul_mod a (pow_mod (mul_mod a a) (b / 2))) let lemma_pow_mod_unfold1 n a b = () #pop-options val lemma_pow_mod_: n:pos{1 < n} -> a:nat_mod n -> b:nat -> Lemma (ensures (pow_mod #n a b == pow a b % n)) (decreases b) let rec lemma_pow_mod_ n a b = if b = 0 then begin lemma_pow0 a; lemma_pow_mod0 a end else begin if b % 2 = 0 then begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold0 n a b } pow_mod #n (mul_mod #n a a) (b / 2); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } pow (mul_mod #n a a) (b / 2) % n; (==) { lemma_pow_mod_base (a * a) (b / 2) n } pow (a * a) (b / 2) % n; (==) { lemma_pow_double a (b / 2) } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end else begin calc (==) { pow_mod #n a b; (==) { lemma_pow_mod_unfold1 n a b } mul_mod a (pow_mod (mul_mod #n a a) (b / 2)); (==) { lemma_pow_mod_ n (mul_mod #n a a) (b / 2) } mul_mod a (pow (mul_mod #n a a) (b / 2) % n); (==) { lemma_pow_mod_base (a * a) (b / 2) n } mul_mod a (pow (a * a) (b / 2) % n); (==) { lemma_pow_double a (b / 2) } mul_mod a (pow a (b / 2 * 2) % n); (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b / 2 * 2)) n } a * pow a (b / 2 * 2) % n; (==) { lemma_pow1 a } pow a 1 * pow a (b / 2 * 2) % n; (==) { lemma_pow_add a 1 (b / 2 * 2) } pow a (b / 2 * 2 + 1) % n; (==) { Math.Lemmas.euclidean_division_definition b 2 } pow a b % n; }; assert (pow_mod #n a b == pow a b % n) end end let lemma_pow_mod #n a b = lemma_pow_mod_ n a b let rec lemma_pow_nat_mod_is_pow #n a b = let k = mk_nat_mod_comm_monoid n in if b = 0 then begin lemma_pow0 a; LE.lemma_pow0 k a end else begin calc (==) { pow a b % n; (==) { lemma_pow_unfold a b } a * pow a (b - 1) % n; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) n } a * (pow a (b - 1) % n) % n; (==) { lemma_pow_nat_mod_is_pow #n a (b - 1) } a * LE.pow k a (b - 1) % n; (==) { } k.LE.mul a (LE.pow k a (b - 1)); (==) { LE.lemma_pow_unfold k a b } LE.pow k a b; }; () end let lemma_add_mod_one #m a = Math.Lemmas.small_mod a m let lemma_add_mod_assoc #m a b c = calc (==) { add_mod (add_mod a b) c; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a + b) c m } ((a + b) + c) % m; (==) { } (a + (b + c)) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_r a (b + c) m } add_mod a (add_mod b c); } let lemma_add_mod_comm #m a b = () let lemma_mod_distributivity_add_right #m a b c = calc (==) { mul_mod a (add_mod b c); (==) { } a * ((b + c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b + c) m } a * (b + c) % m; (==) { Math.Lemmas.distributivity_add_right a b c } (a * b + a * c) % m; (==) { Math.Lemmas.modulo_distributivity (a * b) (a * c) m } add_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_add_left #m a b c = lemma_mod_distributivity_add_right c a b let lemma_mod_distributivity_sub_right #m a b c = calc (==) { mul_mod a (sub_mod b c); (==) { } a * ((b - c) % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r a (b - c) m } a * (b - c) % m; (==) { Math.Lemmas.distributivity_sub_right a b c } (a * b - a * c) % m; (==) { Math.Lemmas.lemma_mod_plus_distr_l (a * b) (- a * c) m } (mul_mod a b - a * c) % m; (==) { Math.Lemmas.lemma_mod_sub_distr (mul_mod a b) (a * c) m } sub_mod (mul_mod a b) (mul_mod a c); } let lemma_mod_distributivity_sub_left #m a b c = lemma_mod_distributivity_sub_right c a b let lemma_inv_mod_both #m a b = let p1 = pow a (m - 2) in let p2 = pow b (m - 2) in calc (==) { mul_mod (inv_mod a) (inv_mod b); (==) { lemma_pow_mod #m a (m - 2); lemma_pow_mod #m b (m - 2) } p1 % m * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l p1 (p2 % m) m } p1 * (p2 % m) % m; (==) { Math.Lemmas.lemma_mod_mul_distr_r p1 p2 m } p1 * p2 % m; (==) { lemma_pow_mul_base a b (m - 2) } pow (a * b) (m - 2) % m; (==) { lemma_pow_mod_base (a * b) (m - 2) m } pow (mul_mod a b) (m - 2) % m; (==) { lemma_pow_mod #m (mul_mod a b) (m - 2) } inv_mod (mul_mod a b); } #push-options "--fuel 1" val pow_eq: a:nat -> n:nat -> Lemma (Fermat.pow a n == pow a n) let rec pow_eq a n = if n = 0 then () else pow_eq a (n - 1) #pop-options let lemma_div_mod_prime #m a = Math.Lemmas.small_mod a m; assert (a == a % m); assert (a <> 0 /\ a % m <> 0); calc (==) { pow_mod #m a (m - 2) * a % m; (==) { lemma_pow_mod #m a (m - 2) } pow a (m - 2) % m * a % m; (==) { Math.Lemmas.lemma_mod_mul_distr_l (pow a (m - 2)) a m } pow a (m - 2) * a % m; (==) { lemma_pow1 a; lemma_pow_add a (m - 2) 1 } pow a (m - 1) % m; (==) { pow_eq a (m - 1) } Fermat.pow a (m - 1) % m; (==) { Fermat.fermat_alt m a } 1; } let lemma_div_mod_prime_one #m a = lemma_pow_mod #m 1 (m - 2); lemma_pow_one (m - 2); Math.Lemmas.small_mod 1 m let lemma_div_mod_prime_cancel #m a b c = calc (==) { mul_mod (mul_mod a c) (inv_mod (mul_mod c b)); (==) { lemma_inv_mod_both c b } mul_mod (mul_mod a c) (mul_mod (inv_mod c) (inv_mod b)); (==) { lemma_mul_mod_assoc (mul_mod a c) (inv_mod c) (inv_mod b) } mul_mod (mul_mod (mul_mod a c) (inv_mod c)) (inv_mod b); (==) { lemma_mul_mod_assoc a c (inv_mod c) } mul_mod (mul_mod a (mul_mod c (inv_mod c))) (inv_mod b); (==) { lemma_div_mod_prime c } mul_mod (mul_mod a 1) (inv_mod b); (==) { Math.Lemmas.small_mod a m } mul_mod a (inv_mod b); } let lemma_div_mod_prime_to_one_denominator #m a b c d = calc (==) { mul_mod (div_mod a c) (div_mod b d); (==) { } mul_mod (mul_mod a (inv_mod c)) (mul_mod b (inv_mod d)); (==) { lemma_mul_mod_comm #m b (inv_mod d); lemma_mul_mod_assoc #m (mul_mod a (inv_mod c)) (inv_mod d) b } mul_mod (mul_mod (mul_mod a (inv_mod c)) (inv_mod d)) b; (==) { lemma_mul_mod_assoc #m a (inv_mod c) (inv_mod d) } mul_mod (mul_mod a (mul_mod (inv_mod c) (inv_mod d))) b; (==) { lemma_inv_mod_both c d } mul_mod (mul_mod a (inv_mod (mul_mod c d))) b; (==) { lemma_mul_mod_assoc #m a (inv_mod (mul_mod c d)) b; lemma_mul_mod_comm #m (inv_mod (mul_mod c d)) b; lemma_mul_mod_assoc #m a b (inv_mod (mul_mod c d)) } mul_mod (mul_mod a b) (inv_mod (mul_mod c d)); } val lemma_div_mod_eq_mul_mod1: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (div_mod a b = c ==> a = mul_mod c b) let lemma_div_mod_eq_mul_mod1 #m a b c = if div_mod a b = c then begin assert (mul_mod (div_mod a b) b = mul_mod c b); calc (==) { mul_mod (div_mod a b) b; (==) { lemma_div_mod_prime_one b } mul_mod (div_mod a b) (div_mod b 1); (==) { lemma_div_mod_prime_to_one_denominator a b b 1 } div_mod (mul_mod a b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel a 1 b } div_mod a 1; (==) { lemma_div_mod_prime_one a } a; } end else () val lemma_div_mod_eq_mul_mod2: #m:prime -> a:nat_mod m -> b:nat_mod m{b <> 0} -> c:nat_mod m -> Lemma (a = mul_mod c b ==> div_mod a b = c) let lemma_div_mod_eq_mul_mod2 #m a b c = if a = mul_mod c b then begin assert (div_mod a b == div_mod (mul_mod c b) b); calc (==) { div_mod (mul_mod c b) b; (==) { Math.Lemmas.small_mod b m } div_mod (mul_mod c b) (mul_mod b 1); (==) { lemma_div_mod_prime_cancel c 1 b } div_mod c 1; (==) { lemma_div_mod_prime_one c } c; } end else () let lemma_div_mod_eq_mul_mod #m a b c = lemma_div_mod_eq_mul_mod1 a b c; lemma_div_mod_eq_mul_mod2 a b c val lemma_mul_mod_zero2: n:pos -> x:int -> y:int -> Lemma (requires x % n == 0 \/ y % n == 0) (ensures x * y % n == 0) let lemma_mul_mod_zero2 n x y = if x % n = 0 then Math.Lemmas.lemma_mod_mul_distr_l x y n else Math.Lemmas.lemma_mod_mul_distr_r x y n let lemma_mul_mod_prime_zero #m a b = Classical.move_requires_3 Euclid.euclid_prime m a b; Classical.move_requires_3 lemma_mul_mod_zero2 m a b val lemma_pow_mod_prime_zero_: #m:prime -> a:nat_mod m -> b:pos -> Lemma (requires pow a b % m = 0) (ensures a = 0)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "Lib.Exponentiation.Definition.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.Classical.fsti.checked", "FStar.Calc.fsti.checked" ], "interface_file": true, "source_file": "Lib.NatMod.fst" }
[ { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "FStar.Math.Euclid", "short_module": "Euclid" }, { "abbrev": true, "full_module": "FStar.Math.Fermat", "short_module": "Fermat" }, { "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": 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": 150, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Lib.NatMod.nat_mod m -> b: Prims.pos -> FStar.Pervasives.Lemma (requires Lib.NatMod.pow a b % m = 0) (ensures a = 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Lib.NatMod.prime", "Lib.NatMod.nat_mod", "Prims.pos", "Prims.op_Equality", "Prims.int", "Lib.NatMod.lemma_pow1", "Prims.bool", "Lib.NatMod.lemma_pow_mod_prime_zero_", "Prims.op_Subtraction", "Prims.unit", "Lib.NatMod.lemma_mul_mod_prime_zero", "FStar.Math.Lemmas.lemma_mod_mul_distr_r", "Lib.NatMod.pow", "Prims._assert", "Prims.b2t", "Prims.op_Modulus", "FStar.Mul.op_Star", "Lib.NatMod.lemma_pow_unfold" ]
[ "recursion" ]
false
false
true
false
false
let rec lemma_pow_mod_prime_zero_ #m a b =
if b = 1 then lemma_pow1 a else let r1 = pow a (b - 1) % m in lemma_pow_unfold a b; assert (a * pow a (b - 1) % m = 0); Math.Lemmas.lemma_mod_mul_distr_r a (pow a (b - 1)) m; lemma_mul_mod_prime_zero #m a r1; if a = 0 then () else lemma_pow_mod_prime_zero_ #m a (b - 1)
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.freeable
val freeable : h: FStar.Monotonic.HyperStack.mem -> p: EverCrypt.AEAD.state a -> Prims.logical
let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p)
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 42, "end_line": 54, "start_col": 0, "start_line": 53 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
h: FStar.Monotonic.HyperStack.mem -> p: EverCrypt.AEAD.state a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.alg", "FStar.Monotonic.HyperStack.mem", "EverCrypt.AEAD.state", "Prims.l_and", "LowStar.Monotonic.Buffer.freeable", "EverCrypt.AEAD.state_s", "LowStar.Buffer.trivial_preorder", "EverCrypt.AEAD.freeable_s", "LowStar.Monotonic.Buffer.deref", "Prims.logical" ]
[]
false
false
false
false
true
let freeable (#a: alg) (h: HS.mem) (p: state a) =
B.freeable p /\ freeable_s (B.deref h p)
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.footprint
val footprint : m: FStar.Monotonic.HyperStack.mem -> s: EverCrypt.AEAD.state a -> Prims.GTot LowStar.Monotonic.Buffer.loc
let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s)))
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 66, "end_line": 62, "start_col": 0, "start_line": 61 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.Monotonic.HyperStack.mem -> s: EverCrypt.AEAD.state a -> Prims.GTot LowStar.Monotonic.Buffer.loc
Prims.GTot
[ "sometrivial" ]
[]
[ "Spec.Agile.AEAD.alg", "FStar.Monotonic.HyperStack.mem", "EverCrypt.AEAD.state", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_addr_of_buffer", "EverCrypt.AEAD.state_s", "LowStar.Buffer.trivial_preorder", "EverCrypt.AEAD.footprint_s", "LowStar.Monotonic.Buffer.deref", "LowStar.Monotonic.Buffer.loc" ]
[]
false
false
false
false
false
let footprint (#a: alg) (m: HS.mem) (s: state a) =
let open B in loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.preserves_freeable
val preserves_freeable (#a: _) (s: state a) (h0 h1: HS.mem) : Type0
val preserves_freeable (#a: _) (s: state a) (h0 h1: HS.mem) : Type0
let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 58, "start_col": 0, "start_line": 57 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p)
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: EverCrypt.AEAD.state a -> h0: FStar.Monotonic.HyperStack.mem -> h1: FStar.Monotonic.HyperStack.mem -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.alg", "EverCrypt.AEAD.state", "FStar.Monotonic.HyperStack.mem", "Prims.l_imp", "EverCrypt.AEAD.freeable" ]
[]
false
false
false
false
true
let preserves_freeable #a (s: state a) (h0: HS.mem) (h1: HS.mem) : Type0 =
freeable h0 s ==> freeable h1 s
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.state
val state : alg: Spec.Agile.AEAD.alg -> Type0
let state alg = B.pointer (state_s alg)
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 39, "end_line": 47, "start_col": 0, "start_line": 47 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
alg: Spec.Agile.AEAD.alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.alg", "LowStar.Buffer.pointer", "EverCrypt.AEAD.state_s" ]
[]
false
false
false
true
true
let state alg =
B.pointer (state_s alg)
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.config_pre
val config_pre : a: Spec.Agile.AEAD.alg -> Prims.logical
let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 13, "end_line": 94, "start_col": 0, "start_line": 86 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.AEAD.alg -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.alg", "Prims.l_and", "Prims.b2t", "EverCrypt.TargetConfig.hacl_can_compile_vale", "Vale.X64.CPU_Features_s.aesni_enabled", "Vale.X64.CPU_Features_s.pclmulqdq_enabled", "Vale.X64.CPU_Features_s.avx_enabled", "Vale.X64.CPU_Features_s.movbe_enabled", "Vale.X64.CPU_Features_s.sse_enabled", "Prims.l_True", "Prims.logical" ]
[]
false
false
false
true
true
let config_pre a =
match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.bytes
val bytes : Type0
let bytes = Seq.seq uint8
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 25, "end_line": 129, "start_col": 0, "start_line": 129 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// -------------------
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Seq.Base.seq", "Spec.Agile.AEAD.uint8" ]
[]
false
false
false
true
true
let bytes =
Seq.seq uint8
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.plain_p
val plain_p : a: Spec.Agile.AEAD.supported_alg -> Type0
let plain_p a = p:B.buffer uint8 { B.length p <= max_length a }
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 63, "end_line": 237, "start_col": 0, "start_line": 237 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a) inline_for_extraction noextract let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False) /// Same function as above, but in the StackInline effect, so that it is possible /// to use AES GCM while staying in the Stack effect. In this case, the state should /// be allocated/deallocated just before/after any encryption or decryption (which /// is not very problematic during, for example, a handshake). inline_for_extraction noextract let alloca_st (a: alg) = k:B.buffer uint8 { B.length k = key_length a } -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> // Sanity invariant h1 s /\ // Memory stuff B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k) /// This function takes a pointer to a caller-allocated reference ``dst`` then, /// if the algorithm is supported (on this platform), allocates a fresh state /// and modifies ``dst`` to point to it. The key-value associated with this can /// be obtained via ``kv (B.deref dst)``; as long as ``dst`` is not modified, /// then the caller can derive that the ``kv`` remains the same, which will be /// required for encrypt. (** @type: true *) [@@ Comment "Create the required AEAD state for the algorithm. Note: The caller must free the AEAD state by calling `EverCrypt_AEAD_free`. @param a The argument `a` must be either of: * `Spec_Agile_AEAD_AES128_GCM` (KEY_LEN=16), * `Spec_Agile_AEAD_AES256_GCM` (KEY_LEN=32), or * `Spec_Agile_AEAD_CHACHA20_POLY1305` (KEY_LEN=32). @param dst Pointer to a pointer where the address of the allocated AEAD state will be written to. @param k Pointer to `KEY_LEN` bytes of memory where the key is read from. The size depends on the used algorithm, see above. @return The function returns `EverCrypt_Error_Success` on success or `EverCrypt_Error_UnsupportedAlgorithm` in case of a bad algorithm identifier. (See `EverCrypt_Error.h`.)"] val create_in: #a:alg -> create_in_st a inline_for_extraction noextract val alloca: #a:alg -> alloca_st a /// Encryption (pre-allocated state) /// -------------------------------- inline_for_extraction noextract let iv_p a = iv:B.buffer uint8 { iv_length a (B.length iv)} inline_for_extraction noextract let ad_p a = ad:B.buffer uint8 { B.length ad <= max_length a }
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.AEAD.supported_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.supported_alg", "LowStar.Buffer.buffer", "Spec.Agile.AEAD.uint8", "Prims.b2t", "FStar.Integers.op_Less_Equals", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "Spec.Agile.AEAD.max_length" ]
[]
false
false
false
true
true
let plain_p a =
p: B.buffer uint8 {B.length p <= max_length a}
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.cipher_p
val cipher_p : a: Spec.Agile.AEAD.alg{Spec.Agile.AEAD.is_supported_alg a} -> Type0
let cipher_p a = p:B.buffer uint8 { B.length p + tag_length a <= max_length a }
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 79, "end_line": 240, "start_col": 0, "start_line": 240 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a) inline_for_extraction noextract let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False) /// Same function as above, but in the StackInline effect, so that it is possible /// to use AES GCM while staying in the Stack effect. In this case, the state should /// be allocated/deallocated just before/after any encryption or decryption (which /// is not very problematic during, for example, a handshake). inline_for_extraction noextract let alloca_st (a: alg) = k:B.buffer uint8 { B.length k = key_length a } -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> // Sanity invariant h1 s /\ // Memory stuff B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k) /// This function takes a pointer to a caller-allocated reference ``dst`` then, /// if the algorithm is supported (on this platform), allocates a fresh state /// and modifies ``dst`` to point to it. The key-value associated with this can /// be obtained via ``kv (B.deref dst)``; as long as ``dst`` is not modified, /// then the caller can derive that the ``kv`` remains the same, which will be /// required for encrypt. (** @type: true *) [@@ Comment "Create the required AEAD state for the algorithm. Note: The caller must free the AEAD state by calling `EverCrypt_AEAD_free`. @param a The argument `a` must be either of: * `Spec_Agile_AEAD_AES128_GCM` (KEY_LEN=16), * `Spec_Agile_AEAD_AES256_GCM` (KEY_LEN=32), or * `Spec_Agile_AEAD_CHACHA20_POLY1305` (KEY_LEN=32). @param dst Pointer to a pointer where the address of the allocated AEAD state will be written to. @param k Pointer to `KEY_LEN` bytes of memory where the key is read from. The size depends on the used algorithm, see above. @return The function returns `EverCrypt_Error_Success` on success or `EverCrypt_Error_UnsupportedAlgorithm` in case of a bad algorithm identifier. (See `EverCrypt_Error.h`.)"] val create_in: #a:alg -> create_in_st a inline_for_extraction noextract val alloca: #a:alg -> alloca_st a /// Encryption (pre-allocated state) /// -------------------------------- inline_for_extraction noextract let iv_p a = iv:B.buffer uint8 { iv_length a (B.length iv)} inline_for_extraction noextract let ad_p a = ad:B.buffer uint8 { B.length ad <= max_length a } inline_for_extraction noextract let plain_p a = p:B.buffer uint8 { B.length p <= max_length a }
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.AEAD.alg{Spec.Agile.AEAD.is_supported_alg a} -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.alg", "Prims.b2t", "Spec.Agile.AEAD.is_supported_alg", "LowStar.Buffer.buffer", "Spec.Agile.AEAD.uint8", "FStar.Integers.op_Less_Equals", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.op_Plus", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "Spec.Agile.AEAD.tag_length", "Spec.Agile.AEAD.max_length" ]
[]
false
false
false
false
true
let cipher_p a =
p: B.buffer uint8 {B.length p + tag_length a <= max_length a}
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.ad_p
val ad_p : a: Spec.Agile.AEAD.supported_alg -> Type0
let ad_p a = ad:B.buffer uint8 { B.length ad <= max_length a }
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 62, "end_line": 234, "start_col": 0, "start_line": 234 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a) inline_for_extraction noextract let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False) /// Same function as above, but in the StackInline effect, so that it is possible /// to use AES GCM while staying in the Stack effect. In this case, the state should /// be allocated/deallocated just before/after any encryption or decryption (which /// is not very problematic during, for example, a handshake). inline_for_extraction noextract let alloca_st (a: alg) = k:B.buffer uint8 { B.length k = key_length a } -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> // Sanity invariant h1 s /\ // Memory stuff B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k) /// This function takes a pointer to a caller-allocated reference ``dst`` then, /// if the algorithm is supported (on this platform), allocates a fresh state /// and modifies ``dst`` to point to it. The key-value associated with this can /// be obtained via ``kv (B.deref dst)``; as long as ``dst`` is not modified, /// then the caller can derive that the ``kv`` remains the same, which will be /// required for encrypt. (** @type: true *) [@@ Comment "Create the required AEAD state for the algorithm. Note: The caller must free the AEAD state by calling `EverCrypt_AEAD_free`. @param a The argument `a` must be either of: * `Spec_Agile_AEAD_AES128_GCM` (KEY_LEN=16), * `Spec_Agile_AEAD_AES256_GCM` (KEY_LEN=32), or * `Spec_Agile_AEAD_CHACHA20_POLY1305` (KEY_LEN=32). @param dst Pointer to a pointer where the address of the allocated AEAD state will be written to. @param k Pointer to `KEY_LEN` bytes of memory where the key is read from. The size depends on the used algorithm, see above. @return The function returns `EverCrypt_Error_Success` on success or `EverCrypt_Error_UnsupportedAlgorithm` in case of a bad algorithm identifier. (See `EverCrypt_Error.h`.)"] val create_in: #a:alg -> create_in_st a inline_for_extraction noextract val alloca: #a:alg -> alloca_st a /// Encryption (pre-allocated state) /// -------------------------------- inline_for_extraction noextract let iv_p a = iv:B.buffer uint8 { iv_length a (B.length iv)}
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.AEAD.supported_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.supported_alg", "LowStar.Buffer.buffer", "Spec.Agile.AEAD.uint8", "Prims.b2t", "FStar.Integers.op_Less_Equals", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "Spec.Agile.AEAD.max_length" ]
[]
false
false
false
true
true
let ad_p a =
ad: B.buffer uint8 {B.length ad <= max_length a}
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.iv_p
val iv_p : a: Spec.Agile.AEAD.supported_alg -> Type0
let iv_p a = iv:B.buffer uint8 { iv_length a (B.length iv)}
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 59, "end_line": 231, "start_col": 0, "start_line": 231 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a) inline_for_extraction noextract let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False) /// Same function as above, but in the StackInline effect, so that it is possible /// to use AES GCM while staying in the Stack effect. In this case, the state should /// be allocated/deallocated just before/after any encryption or decryption (which /// is not very problematic during, for example, a handshake). inline_for_extraction noextract let alloca_st (a: alg) = k:B.buffer uint8 { B.length k = key_length a } -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> // Sanity invariant h1 s /\ // Memory stuff B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k) /// This function takes a pointer to a caller-allocated reference ``dst`` then, /// if the algorithm is supported (on this platform), allocates a fresh state /// and modifies ``dst`` to point to it. The key-value associated with this can /// be obtained via ``kv (B.deref dst)``; as long as ``dst`` is not modified, /// then the caller can derive that the ``kv`` remains the same, which will be /// required for encrypt. (** @type: true *) [@@ Comment "Create the required AEAD state for the algorithm. Note: The caller must free the AEAD state by calling `EverCrypt_AEAD_free`. @param a The argument `a` must be either of: * `Spec_Agile_AEAD_AES128_GCM` (KEY_LEN=16), * `Spec_Agile_AEAD_AES256_GCM` (KEY_LEN=32), or * `Spec_Agile_AEAD_CHACHA20_POLY1305` (KEY_LEN=32). @param dst Pointer to a pointer where the address of the allocated AEAD state will be written to. @param k Pointer to `KEY_LEN` bytes of memory where the key is read from. The size depends on the used algorithm, see above. @return The function returns `EverCrypt_Error_Success` on success or `EverCrypt_Error_UnsupportedAlgorithm` in case of a bad algorithm identifier. (See `EverCrypt_Error.h`.)"] val create_in: #a:alg -> create_in_st a inline_for_extraction noextract val alloca: #a:alg -> alloca_st a /// Encryption (pre-allocated state) /// --------------------------------
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.AEAD.supported_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.supported_alg", "LowStar.Buffer.buffer", "Spec.Agile.AEAD.uint8", "Spec.Agile.AEAD.iv_length", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder" ]
[]
false
false
false
true
true
let iv_p a =
iv: B.buffer uint8 {iv_length a (B.length iv)}
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.encrypt_live_disjoint_pre
val encrypt_live_disjoint_pre : a: Spec.Agile.AEAD.supported_alg -> iv: EverCrypt.AEAD.iv_p a -> iv_len: FStar.UInt32.t -> ad: EverCrypt.AEAD.ad_p a -> ad_len: FStar.UInt32.t -> plain: EverCrypt.AEAD.plain_p a -> plain_len: FStar.UInt32.t -> cipher: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> tag: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> h0: FStar.Monotonic.HyperStack.mem -> Prims.logical
let encrypt_live_disjoint_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = MB.(all_live h0 [ buf iv; buf ad; buf plain; buf cipher; buf tag ]) /\ (B.disjoint plain cipher \/ plain == cipher) /\ B.disjoint cipher tag /\ B.disjoint iv cipher /\ B.disjoint iv tag /\ B.disjoint plain tag /\ B.disjoint plain ad /\ B.disjoint ad cipher /\ B.disjoint ad tag
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 43, "end_line": 279, "start_col": 0, "start_line": 262 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a) inline_for_extraction noextract let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False) /// Same function as above, but in the StackInline effect, so that it is possible /// to use AES GCM while staying in the Stack effect. In this case, the state should /// be allocated/deallocated just before/after any encryption or decryption (which /// is not very problematic during, for example, a handshake). inline_for_extraction noextract let alloca_st (a: alg) = k:B.buffer uint8 { B.length k = key_length a } -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> // Sanity invariant h1 s /\ // Memory stuff B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k) /// This function takes a pointer to a caller-allocated reference ``dst`` then, /// if the algorithm is supported (on this platform), allocates a fresh state /// and modifies ``dst`` to point to it. The key-value associated with this can /// be obtained via ``kv (B.deref dst)``; as long as ``dst`` is not modified, /// then the caller can derive that the ``kv`` remains the same, which will be /// required for encrypt. (** @type: true *) [@@ Comment "Create the required AEAD state for the algorithm. Note: The caller must free the AEAD state by calling `EverCrypt_AEAD_free`. @param a The argument `a` must be either of: * `Spec_Agile_AEAD_AES128_GCM` (KEY_LEN=16), * `Spec_Agile_AEAD_AES256_GCM` (KEY_LEN=32), or * `Spec_Agile_AEAD_CHACHA20_POLY1305` (KEY_LEN=32). @param dst Pointer to a pointer where the address of the allocated AEAD state will be written to. @param k Pointer to `KEY_LEN` bytes of memory where the key is read from. The size depends on the used algorithm, see above. @return The function returns `EverCrypt_Error_Success` on success or `EverCrypt_Error_UnsupportedAlgorithm` in case of a bad algorithm identifier. (See `EverCrypt_Error.h`.)"] val create_in: #a:alg -> create_in_st a inline_for_extraction noextract val alloca: #a:alg -> alloca_st a /// Encryption (pre-allocated state) /// -------------------------------- inline_for_extraction noextract let iv_p a = iv:B.buffer uint8 { iv_length a (B.length iv)} inline_for_extraction noextract let ad_p a = ad:B.buffer uint8 { B.length ad <= max_length a } inline_for_extraction noextract let plain_p a = p:B.buffer uint8 { B.length p <= max_length a } inline_for_extraction noextract let cipher_p a = p:B.buffer uint8 { B.length p + tag_length a <= max_length a } // SNIPPET_START: encrypt_pre inline_for_extraction noextract let encrypt_gen_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = v iv_len = B.length iv /\ v iv_len > 0 /\ v ad_len = B.length ad /\ v ad_len <= pow2 31 /\ v plain_len = B.length plain /\ v plain_len <= max_length a /\ B.length cipher = B.length plain /\ B.length tag = tag_length a
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.AEAD.supported_alg -> iv: EverCrypt.AEAD.iv_p a -> iv_len: FStar.UInt32.t -> ad: EverCrypt.AEAD.ad_p a -> ad_len: FStar.UInt32.t -> plain: EverCrypt.AEAD.plain_p a -> plain_len: FStar.UInt32.t -> cipher: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> tag: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> h0: FStar.Monotonic.HyperStack.mem -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.supported_alg", "EverCrypt.AEAD.iv_p", "FStar.UInt32.t", "EverCrypt.AEAD.ad_p", "EverCrypt.AEAD.plain_p", "LowStar.Buffer.buffer", "Spec.Agile.AEAD.uint8", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.all_live", "Prims.Cons", "LowStar.Monotonic.Buffer.buf_t", "LowStar.Monotonic.Buffer.buf", "LowStar.Buffer.trivial_preorder", "Prims.Nil", "Prims.l_or", "LowStar.Monotonic.Buffer.disjoint", "Prims.eq2", "Prims.logical" ]
[]
false
false
false
false
true
let encrypt_live_disjoint_pre (a: supported_alg) (iv: iv_p a) (iv_len: UInt32.t) (ad: ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher tag: B.buffer uint8) (h0: HS.mem) =
MB.(all_live h0 [buf iv; buf ad; buf plain; buf cipher; buf tag]) /\ (B.disjoint plain cipher \/ plain == cipher) /\ B.disjoint cipher tag /\ B.disjoint iv cipher /\ B.disjoint iv tag /\ B.disjoint plain tag /\ B.disjoint plain ad /\ B.disjoint ad cipher /\ B.disjoint ad tag
false
FStar.UInt8.fsti
FStar.UInt8.eq_mask
val eq_mask (a b: t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)))
val eq_mask (a b: t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0)))
let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 283, "start_col": 0, "start_line": 256 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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": 80, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.t", "Prims.unit", "Prims.op_Equality", "Prims._assert", "Prims.b2t", "FStar.UInt.uint_t", "FStar.UInt8.n", "FStar.UInt8.v", "FStar.UInt.ones", "Prims.l_and", "Prims.int", "FStar.UInt.logor_lemma_1", "FStar.UInt.lognot_lemma_1", "FStar.UInt.logxor_self", "Prims.bool", "FStar.UInt.zero", "FStar.UInt.lemma_minus_zero", "FStar.UInt.lemma_msb_pow2", "FStar.UInt8.lognot", "FStar.UInt.logxor_neq_nonzero", "FStar.UInt8.sub_mod", "FStar.UInt8.uint_to_t", "FStar.UInt8.shift_right", "FStar.UInt8.n_minus_one", "FStar.UInt8.logor", "FStar.UInt8.minus", "FStar.UInt8.logxor", "Prims.l_True", "Prims.l_imp", "Prims.op_Subtraction", "Prims.pow2", "Prims.op_disEquality" ]
[]
false
false
false
false
false
let eq_mask (a b: t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) =
let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then (logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n)) else (logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n)); c
false
FStar.UInt8.fsti
FStar.UInt8.gte_mask
val gte_mask (a b: t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)))
val gte_mask (a b: t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0)))
let gte_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) = let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c
{ "file_name": "ulib/FStar.UInt8.fsti", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 312, "start_col": 0, "start_line": 295 }
(* Copyright 2008-2019 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.UInt8 (**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****) unfold let n = 8 /// For FStar.UIntN.fstp: anything that you fix/update here should be /// reflected in [FStar.IntN.fstp], which is mostly a copy-paste of /// this module. /// /// Except, as compared to [FStar.IntN.fstp], here: /// - every occurrence of [int_t] has been replaced with [uint_t] /// - every occurrence of [@%] has been replaced with [%]. /// - some functions (e.g., add_underspec, etc.) are only defined here, not on signed integers /// This module provides an abstract type for machine integers of a /// given signedness and width. The interface is designed to be safe /// with respect to arithmetic underflow and overflow. /// Note, we have attempted several times to re-design this module to /// make it more amenable to normalization and to impose less overhead /// on the SMT solver when reasoning about machine integer /// arithmetic. The following github issue reports on the current /// status of that work. /// /// https://github.com/FStarLang/FStar/issues/1757 open FStar.UInt open FStar.Mul #set-options "--max_fuel 0 --max_ifuel 0" (** Abstract type of machine integers, with an underlying representation using a bounded mathematical integer *) new val t : eqtype (** A coercion that projects a bounded mathematical integer from a machine integer *) val v (x:t) : Tot (uint_t n) (** A coercion that injects a bounded mathematical integers into a machine integer *) val uint_to_t (x:uint_t n) : Pure t (requires True) (ensures (fun y -> v y = x)) (** Injection/projection inverse *) val uv_inv (x : t) : Lemma (ensures (uint_to_t (v x) == x)) [SMTPat (v x)] (** Projection/injection inverse *) val vu_inv (x : uint_t n) : Lemma (ensures (v (uint_to_t x) == x)) [SMTPat (uint_to_t x)] (** An alternate form of the injectivity of the [v] projection *) val v_inj (x1 x2: t): Lemma (requires (v x1 == v x2)) (ensures (x1 == x2)) (** Constants 0 and 1 *) val zero : x:t{v x = 0} val one : x:t{v x = 1} (**** Addition primitives *) (** Bounds-respecting addition The precondition enforces that the sum does not overflow, expressing the bound as an addition on mathematical integers *) val add (a:t) (b:t) : Pure t (requires (size (v a + v b) n)) (ensures (fun c -> v a + v b = v c)) (** Underspecified, possibly overflowing addition: The postcondition only enures that the result is the sum of the arguments in case there is no overflow *) val add_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a + v b) n ==> v a + v b = v c)) (** Addition modulo [2^n] Machine integers can always be added, but the postcondition is now in terms of addition modulo [2^n] on mathematical integers *) val add_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) (**** Subtraction primitives *) (** Bounds-respecting subtraction The precondition enforces that the difference does not underflow, expressing the bound as a difference on mathematical integers *) val sub (a:t) (b:t) : Pure t (requires (size (v a - v b) n)) (ensures (fun c -> v a - v b = v c)) (** Underspecified, possibly overflowing subtraction: The postcondition only enures that the result is the difference of the arguments in case there is no underflow *) val sub_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a - v b) n ==> v a - v b = v c)) (** Subtraction modulo [2^n] Machine integers can always be subtractd, but the postcondition is now in terms of subtraction modulo [2^n] on mathematical integers *) val sub_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) (**** Multiplication primitives *) (** Bounds-respecting multiplication The precondition enforces that the product does not overflow, expressing the bound as a product on mathematical integers *) val mul (a:t) (b:t) : Pure t (requires (size (v a * v b) n)) (ensures (fun c -> v a * v b = v c)) (** Underspecified, possibly overflowing product The postcondition only enures that the result is the product of the arguments in case there is no overflow *) val mul_underspec (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> size (v a * v b) n ==> v a * v b = v c)) (** Multiplication modulo [2^n] Machine integers can always be multiplied, but the postcondition is now in terms of product modulo [2^n] on mathematical integers *) val mul_mod (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) (**** Division primitives *) (** Euclidean division of [a] and [b], with [b] non-zero *) val div (a:t) (b:t{v b <> 0}) : Pure t (requires (True)) (ensures (fun c -> v a / v b = v c)) (**** Modulo primitives *) (** Euclidean remainder The result is the modulus of [a] with respect to a non-zero [b] *) val rem (a:t) (b:t{v b <> 0}) : Pure t (requires True) (ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) (**** Bitwise operators *) /// Also see FStar.BV (** Bitwise logical conjunction *) val logand (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logand` v y = v z)) (** Bitwise logical exclusive-or *) val logxor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logxor` v y == v z)) (** Bitwise logical disjunction *) val logor (x:t) (y:t) : Pure t (requires True) (ensures (fun z -> v x `logor` v y == v z)) (** Bitwise logical negation *) val lognot (x:t) : Pure t (requires True) (ensures (fun z -> lognot (v x) == v z)) (**** Shift operators *) (** Shift right with zero fill, shifting at most the integer width *) val shift_right (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) (** Shift left with zero fill, shifting at most the integer width *) val shift_left (a:t) (s:UInt32.t) : Pure t (requires (UInt32.v s < n)) (ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) (**** Comparison operators *) (** Equality Note, it is safe to also use the polymorphic decidable equality operator [=] *) let eq (a:t) (b:t) : Tot bool = eq #n (v a) (v b) (** Greater than *) let gt (a:t) (b:t) : Tot bool = gt #n (v a) (v b) (** Greater than or equal *) let gte (a:t) (b:t) : Tot bool = gte #n (v a) (v b) (** Less than *) let lt (a:t) (b:t) : Tot bool = lt #n (v a) (v b) (** Less than or equal *) let lte (a:t) (b:t) : Tot bool = lte #n (v a) (v b) (** Unary negation *) inline_for_extraction let minus (a:t) = add_mod (lognot a) (uint_to_t 1) (** The maximum shift value for this type, i.e. its width minus one, as an UInt32. *) inline_for_extraction let n_minus_one = UInt32.uint_to_t (n - 1) #set-options "--z3rlimit 80 --initial_fuel 1 --max_fuel 1" (** A constant-time way to compute the equality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=2e60bb395c1f589a398ec606d611132ef9ef764b Note, the branching on [a=b] is just for proof-purposes. *) [@ CNoInline ] let eq_mask (a:t) (b:t) : Pure t (requires True) (ensures (fun c -> (v a = v b ==> v c = pow2 n - 1) /\ (v a <> v b ==> v c = 0))) = let x = logxor a b in let minus_x = minus x in let x_or_minus_x = logor x minus_x in let xnx = shift_right x_or_minus_x n_minus_one in let c = sub_mod xnx (uint_to_t 1) in if a = b then begin logxor_self (v a); lognot_lemma_1 #n; logor_lemma_1 (v x); assert (v x = 0 /\ v minus_x = 0 /\ v x_or_minus_x = 0 /\ v xnx = 0); assert (v c = ones n) end else begin logxor_neq_nonzero (v a) (v b); lemma_msb_pow2 #n (v (lognot x)); lemma_msb_pow2 #n (v minus_x); lemma_minus_zero #n (v x); assert (v c = FStar.UInt.zero n) end; c private val lemma_sub_msbs (a:t) (b:t) : Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) (** A constant-time way to compute the [>=] inequality of two machine integers. With inspiration from https://git.zx2c4.com/WireGuard/commit/src/crypto/curve25519-hacl64.h?id=0a483a9b431d87eca1b275463c632f8d5551978a *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.UInt32.fsti.checked", "FStar.UInt.fsti.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "FStar.UInt8.fsti" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.UInt", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 1, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_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": 80, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t
Prims.Pure
[]
[]
[ "FStar.UInt8.t", "Prims.unit", "FStar.UInt.lemma_msb_gte", "FStar.UInt8.n", "FStar.UInt8.v", "FStar.UInt8.lemma_sub_msbs", "FStar.UInt8.sub_mod", "FStar.UInt8.uint_to_t", "FStar.UInt8.shift_right", "FStar.UInt8.n_minus_one", "FStar.UInt8.logxor", "FStar.UInt8.logor", "Prims.l_True", "Prims.l_and", "Prims.l_imp", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_Equality", "Prims.int", "Prims.op_Subtraction", "Prims.pow2", "Prims.op_LessThan" ]
[]
false
false
false
false
false
let gte_mask (a b: t) : Pure t (requires True) (ensures (fun c -> (v a >= v b ==> v c = pow2 n - 1) /\ (v a < v b ==> v c = 0))) =
let x = a in let y = b in let x_xor_y = logxor x y in let x_sub_y = sub_mod x y in let x_sub_y_xor_y = logxor x_sub_y y in let q = logor x_xor_y x_sub_y_xor_y in let x_xor_q = logxor x q in let x_xor_q_ = shift_right x_xor_q n_minus_one in let c = sub_mod x_xor_q_ (uint_to_t 1) in lemma_sub_msbs x y; lemma_msb_gte (v x) (v y); lemma_msb_gte (v y) (v x); c
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.invariant
val invariant : m: FStar.Monotonic.HyperStack.mem -> s: EverCrypt.AEAD.state a -> Prims.logical
let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0)
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 103, "start_col": 0, "start_line": 100 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
m: FStar.Monotonic.HyperStack.mem -> s: EverCrypt.AEAD.state a -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.alg", "FStar.Monotonic.HyperStack.mem", "EverCrypt.AEAD.state", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "EverCrypt.AEAD.state_s", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.loc_addr_of_buffer", "EverCrypt.AEAD.footprint_s", "LowStar.Monotonic.Buffer.deref", "EverCrypt.AEAD.invariant_s", "LowStar.Monotonic.Buffer.get", "Prims.logical" ]
[]
false
false
false
false
true
let invariant (#a: alg) (m: HS.mem) (s: state a) =
B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0)
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.g
val g (p: prop) : Steel unit emp (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p)
val g (p: prop) : Steel unit emp (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p)
let g (p:prop) : Steel unit emp (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p) = let f2 (p:prop) : SteelT (u:unit{p}) emp (fun _ -> emp) = f_ref p in let x = f2 p in x
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 19, "end_line": 179, "start_col": 0, "start_line": 173 }
(* 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) // in the postcondition let test7 (_:unit) : SteelT ref emp ptr = let r = alloc 0 in let x = read r in write r 0; r let test8 (b1 b2 b3:ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = write b2 0 open Steel.Effect.Atomic let test_if1 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then noop () else noop () let test_if2 (b:bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then write r 0 else write r 1 let test_if3 (b:bool) (r:ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then noop () else noop () let test_if4 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then (let r = alloc 0 in free r) else (noop ()) let test_if5 (b:bool) : SteelT ref emp (fun r -> ptr r) = if b then alloc 0 else alloc 1 let test_if6 (b:bool) : SteelT ref emp (fun r -> ptr r) = let r = if b then alloc 0 else alloc 1 in let x = read r in write r 0; r (* First test with different (but equivalent) slprops in both branches *) let test_if7 (b:bool) (r1 r2: ref) : SteelT unit (ptr r1 `star` ptr r2) (fun _ -> ptr r1 `star` ptr r2) = if b then (write r1 0; write r2 0) else (write r2 0; write r1 0); write r2 0 (* Test with different slprops in both branches. The second branch captures the outer frame in its context *) let test_if8 (b:bool) (r1 r2: ref) : SteelT unit (ptr r1 `star` ptr r2) (fun _ -> ptr r1 `star` ptr r2) = if b then (write r1 0; write r2 0) else (write r2 0); write r2 0 let test_if9 (b:bool) (r1 r2: ref) : SteelT unit (ptr r1 `star` ptr r2) (fun _ -> ptr r1 `star` ptr r2) = write r1 0; if b then (write r1 0) else (write r2 0); write r2 0; if b then (write r1 0) else (write r2 0); write r1 0 (* Leave out some extra slprop outside of if_then_else *) let test_if10 (b:bool) (r1 r2 r3: ref) : SteelT unit (ptr r1 `star` ptr r2 `star` ptr r3) (fun _ -> ptr r1 `star` ptr r2 `star` ptr r3) = if b then (write r1 0; write r2 0) else (write r2 0; write r1 0); write r2 0 (* Tests if_then_else depending on previously created local var *) let test_if11 () : SteelT ref emp ptr = let r = alloc 0 in if true then return r else return r // Test for refinement types in return values. cf PR 2227 assume val f_ref (p:prop) : SteelT (u:unit{p}) emp (fun _ -> emp)
{ "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.Atomic", "short_module": null }, { "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
p: Prims.prop -> Steel.Effect.Steel Prims.unit
Steel.Effect.Steel
[]
[]
[ "Prims.prop", "Prims.unit", "Steel.Effect.Common.emp", "Steel.Effect.Common.vprop", "SteelFramingTestSuite.f_ref", "Steel.Effect.Common.rmem", "Prims.l_True" ]
[]
false
true
false
false
false
let g (p: prop) : Steel unit emp (fun _ -> emp) (requires fun _ -> True) (ensures fun _ _ _ -> p) =
let f2 (p: prop) : SteelT (u: unit{p}) emp (fun _ -> emp) = f_ref p in let x = f2 p in x
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.loc_includes_union_l_footprint_s
val loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires (B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s))) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))]
val loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires (B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s))) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))]
let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s)
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 46, "end_line": 82, "start_col": 0, "start_line": 74 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.)
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l1: LowStar.Monotonic.Buffer.loc -> l2: LowStar.Monotonic.Buffer.loc -> s: EverCrypt.AEAD.state_s a -> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.loc_includes l1 (EverCrypt.AEAD.footprint_s s) \/ LowStar.Monotonic.Buffer.loc_includes l2 (EverCrypt.AEAD.footprint_s s)) (ensures LowStar.Monotonic.Buffer.loc_includes (LowStar.Monotonic.Buffer.loc_union l1 l2) (EverCrypt.AEAD.footprint_s s)) [ SMTPat (LowStar.Monotonic.Buffer.loc_includes (LowStar.Monotonic.Buffer.loc_union l1 l2) (EverCrypt.AEAD.footprint_s s)) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowStar.Monotonic.Buffer.loc", "Spec.Agile.AEAD.alg", "EverCrypt.AEAD.state_s", "LowStar.Monotonic.Buffer.loc_includes_union_l", "EverCrypt.AEAD.footprint_s", "Prims.unit", "Prims.l_or", "LowStar.Monotonic.Buffer.loc_includes", "Prims.squash", "LowStar.Monotonic.Buffer.loc_union", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
true
false
true
false
false
let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires (B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s))) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] =
B.loc_includes_union_l l1 l2 (footprint_s s)
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.create_in_st
val create_in_st : a: Spec.Agile.AEAD.alg -> Type0
let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False)
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 174, "start_col": 0, "start_line": 147 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a)
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.AEAD.alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.alg", "FStar.Monotonic.HyperHeap.rid", "LowStar.Buffer.pointer", "LowStar.Buffer.pointer_or_null", "EverCrypt.AEAD.state_s", "LowStar.Buffer.buffer", "Spec.Agile.AEAD.uint8", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "Spec.Agile.AEAD.key_length", "EverCrypt.Error.error_code", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "FStar.HyperStack.ST.is_eternal_region", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Spec.Agile.AEAD.is_supported_alg", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "EverCrypt.AEAD.invariant", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Monotonic.Buffer.fresh_loc", "EverCrypt.AEAD.footprint", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_region_only", "EverCrypt.AEAD.freeable", "Prims.eq2", "FStar.Seq.Base.seq", "EverCrypt.AEAD.as_kv", "LowStar.Monotonic.Buffer.deref", "LowStar.Monotonic.Buffer.as_seq", "Prims.l_False" ]
[]
false
false
false
true
true
let create_in_st (a: alg) =
r: HS.rid -> dst: B.pointer (B.pointer_or_null (state_s a)) -> k: B.buffer uint8 {B.length k = key_length a} -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> let open B in modifies loc_none h0 h1 | Success -> let s = B.deref h1 dst in is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False)
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.encrypt_pre
val encrypt_pre : a: Spec.Agile.AEAD.supported_alg -> s: LowStar.Buffer.pointer_or_null (EverCrypt.AEAD.state_s a) -> iv: EverCrypt.AEAD.iv_p a -> iv_len: FStar.UInt32.t -> ad: EverCrypt.AEAD.ad_p a -> ad_len: FStar.UInt32.t -> plain: EverCrypt.AEAD.plain_p a -> plain_len: FStar.UInt32.t -> cipher: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> tag: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> h0: FStar.Monotonic.HyperStack.mem -> Prims.logical
let encrypt_pre (a: supported_alg) (s:B.pointer_or_null (state_s a)) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = encrypt_gen_pre a iv iv_len ad ad_len plain plain_len cipher tag h0 /\ ( not (B.g_is_null s) ==> invariant h0 s /\ B.(loc_disjoint (footprint h0 s) (loc_buffer iv)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer ad)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer tag)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer plain)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer cipher)) /\ encrypt_live_disjoint_pre a iv iv_len ad ad_len plain plain_len cipher tag h0)
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 82, "end_line": 302, "start_col": 0, "start_line": 282 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a) inline_for_extraction noextract let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False) /// Same function as above, but in the StackInline effect, so that it is possible /// to use AES GCM while staying in the Stack effect. In this case, the state should /// be allocated/deallocated just before/after any encryption or decryption (which /// is not very problematic during, for example, a handshake). inline_for_extraction noextract let alloca_st (a: alg) = k:B.buffer uint8 { B.length k = key_length a } -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> // Sanity invariant h1 s /\ // Memory stuff B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k) /// This function takes a pointer to a caller-allocated reference ``dst`` then, /// if the algorithm is supported (on this platform), allocates a fresh state /// and modifies ``dst`` to point to it. The key-value associated with this can /// be obtained via ``kv (B.deref dst)``; as long as ``dst`` is not modified, /// then the caller can derive that the ``kv`` remains the same, which will be /// required for encrypt. (** @type: true *) [@@ Comment "Create the required AEAD state for the algorithm. Note: The caller must free the AEAD state by calling `EverCrypt_AEAD_free`. @param a The argument `a` must be either of: * `Spec_Agile_AEAD_AES128_GCM` (KEY_LEN=16), * `Spec_Agile_AEAD_AES256_GCM` (KEY_LEN=32), or * `Spec_Agile_AEAD_CHACHA20_POLY1305` (KEY_LEN=32). @param dst Pointer to a pointer where the address of the allocated AEAD state will be written to. @param k Pointer to `KEY_LEN` bytes of memory where the key is read from. The size depends on the used algorithm, see above. @return The function returns `EverCrypt_Error_Success` on success or `EverCrypt_Error_UnsupportedAlgorithm` in case of a bad algorithm identifier. (See `EverCrypt_Error.h`.)"] val create_in: #a:alg -> create_in_st a inline_for_extraction noextract val alloca: #a:alg -> alloca_st a /// Encryption (pre-allocated state) /// -------------------------------- inline_for_extraction noextract let iv_p a = iv:B.buffer uint8 { iv_length a (B.length iv)} inline_for_extraction noextract let ad_p a = ad:B.buffer uint8 { B.length ad <= max_length a } inline_for_extraction noextract let plain_p a = p:B.buffer uint8 { B.length p <= max_length a } inline_for_extraction noextract let cipher_p a = p:B.buffer uint8 { B.length p + tag_length a <= max_length a } // SNIPPET_START: encrypt_pre inline_for_extraction noextract let encrypt_gen_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = v iv_len = B.length iv /\ v iv_len > 0 /\ v ad_len = B.length ad /\ v ad_len <= pow2 31 /\ v plain_len = B.length plain /\ v plain_len <= max_length a /\ B.length cipher = B.length plain /\ B.length tag = tag_length a inline_for_extraction noextract let encrypt_live_disjoint_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = MB.(all_live h0 [ buf iv; buf ad; buf plain; buf cipher; buf tag ]) /\ (B.disjoint plain cipher \/ plain == cipher) /\ B.disjoint cipher tag /\ B.disjoint iv cipher /\ B.disjoint iv tag /\ B.disjoint plain tag /\ B.disjoint plain ad /\ B.disjoint ad cipher /\ B.disjoint ad tag
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.AEAD.supported_alg -> s: LowStar.Buffer.pointer_or_null (EverCrypt.AEAD.state_s a) -> iv: EverCrypt.AEAD.iv_p a -> iv_len: FStar.UInt32.t -> ad: EverCrypt.AEAD.ad_p a -> ad_len: FStar.UInt32.t -> plain: EverCrypt.AEAD.plain_p a -> plain_len: FStar.UInt32.t -> cipher: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> tag: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> h0: FStar.Monotonic.HyperStack.mem -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.supported_alg", "LowStar.Buffer.pointer_or_null", "EverCrypt.AEAD.state_s", "EverCrypt.AEAD.iv_p", "FStar.UInt32.t", "EverCrypt.AEAD.ad_p", "EverCrypt.AEAD.plain_p", "LowStar.Buffer.buffer", "Spec.Agile.AEAD.uint8", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverCrypt.AEAD.encrypt_gen_pre", "Prims.l_imp", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.trivial_preorder", "EverCrypt.AEAD.invariant", "LowStar.Monotonic.Buffer.loc_disjoint", "EverCrypt.AEAD.footprint", "LowStar.Monotonic.Buffer.loc_buffer", "EverCrypt.AEAD.encrypt_live_disjoint_pre", "Prims.logical" ]
[]
false
false
false
false
true
let encrypt_pre (a: supported_alg) (s: B.pointer_or_null (state_s a)) (iv: iv_p a) (iv_len: UInt32.t) (ad: ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher tag: B.buffer uint8) (h0: HS.mem) =
encrypt_gen_pre a iv iv_len ad ad_len plain plain_len cipher tag h0 /\ (not (B.g_is_null s) ==> invariant h0 s /\ B.(loc_disjoint (footprint h0 s) (loc_buffer iv)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer ad)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer tag)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer plain)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer cipher)) /\ encrypt_live_disjoint_pre a iv iv_len ad ad_len plain plain_len cipher tag h0)
false
Steel.ST.HigherArray.fst
Steel.ST.HigherArray.pts_to_not_null
val pts_to_not_null (#opened: _) (#elt: Type u#1) (#p: P.perm) (a: array elt) (s: Seq.seq elt) : STGhost unit opened (pts_to a p s) (fun _ -> pts_to a p s) (True) (fun _ -> a =!= null)
val pts_to_not_null (#opened: _) (#elt: Type u#1) (#p: P.perm) (a: array elt) (s: Seq.seq elt) : STGhost unit opened (pts_to a p s) (fun _ -> pts_to a p s) (True) (fun _ -> a =!= null)
let pts_to_not_null a s = elim_pts_to a _ s; R.pts_to_not_null _ _; intro_pts_to a _ s
{ "file_name": "lib/steel/Steel.ST.HigherArray.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 20, "end_line": 190, "start_col": 0, "start_line": 186 }
(* 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
{ "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
a: Steel.ST.HigherArray.array elt -> s: FStar.Seq.Base.seq elt -> Steel.ST.Effect.Ghost.STGhost Prims.unit
Steel.ST.Effect.Ghost.STGhost
[]
[]
[ "Steel.Memory.inames", "Steel.FractionalPermission.perm", "Steel.ST.HigherArray.array", "FStar.Seq.Base.seq", "Steel.ST.HigherArray.intro_pts_to", "Steel.ST.HigherArray.mk_carrier", "FStar.SizeT.v", "FStar.Ghost.reveal", "FStar.SizeT.t", "Steel.ST.HigherArray.__proj__Mkptr__item__base_len", "Steel.ST.HigherArray.ptr_of", "Steel.ST.HigherArray.__proj__Mkptr__item__offset", "Prims.unit", "Steel.ST.PCMReference.pts_to_not_null", "Steel.ST.HigherArray.carrier", "FStar.Ghost.hide", "Prims.nat", "Steel.ST.HigherArray.pcm", "Steel.ST.HigherArray.__proj__Mkptr__item__base", "Steel.ST.HigherArray.elim_pts_to" ]
[]
false
true
false
false
false
let pts_to_not_null a s =
elim_pts_to a _ s; R.pts_to_not_null _ _; intro_pts_to a _ s
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.encrypt_expand_pre
val encrypt_expand_pre : a: Spec.Agile.AEAD.supported_alg -> k: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 {LowStar.Monotonic.Buffer.length k = Spec.Agile.AEAD.key_length a} -> iv: EverCrypt.AEAD.iv_p a -> iv_len: FStar.UInt32.t -> ad: EverCrypt.AEAD.ad_p a -> ad_len: FStar.UInt32.t -> plain: EverCrypt.AEAD.plain_p a -> plain_len: FStar.UInt32.t -> cipher: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> tag: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> h0: FStar.Monotonic.HyperStack.mem -> Prims.logical
let encrypt_expand_pre (a: supported_alg) (k:B.buffer uint8 { B.length k = key_length a }) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = encrypt_gen_pre a iv iv_len ad ad_len plain plain_len cipher tag h0 /\ ( B.live h0 k /\ B.disjoint k cipher /\ encrypt_live_disjoint_pre a iv iv_len ad ad_len plain plain_len cipher tag h0)
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 58, "end_line": 383, "start_col": 0, "start_line": 368 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a) inline_for_extraction noextract let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False) /// Same function as above, but in the StackInline effect, so that it is possible /// to use AES GCM while staying in the Stack effect. In this case, the state should /// be allocated/deallocated just before/after any encryption or decryption (which /// is not very problematic during, for example, a handshake). inline_for_extraction noextract let alloca_st (a: alg) = k:B.buffer uint8 { B.length k = key_length a } -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> // Sanity invariant h1 s /\ // Memory stuff B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k) /// This function takes a pointer to a caller-allocated reference ``dst`` then, /// if the algorithm is supported (on this platform), allocates a fresh state /// and modifies ``dst`` to point to it. The key-value associated with this can /// be obtained via ``kv (B.deref dst)``; as long as ``dst`` is not modified, /// then the caller can derive that the ``kv`` remains the same, which will be /// required for encrypt. (** @type: true *) [@@ Comment "Create the required AEAD state for the algorithm. Note: The caller must free the AEAD state by calling `EverCrypt_AEAD_free`. @param a The argument `a` must be either of: * `Spec_Agile_AEAD_AES128_GCM` (KEY_LEN=16), * `Spec_Agile_AEAD_AES256_GCM` (KEY_LEN=32), or * `Spec_Agile_AEAD_CHACHA20_POLY1305` (KEY_LEN=32). @param dst Pointer to a pointer where the address of the allocated AEAD state will be written to. @param k Pointer to `KEY_LEN` bytes of memory where the key is read from. The size depends on the used algorithm, see above. @return The function returns `EverCrypt_Error_Success` on success or `EverCrypt_Error_UnsupportedAlgorithm` in case of a bad algorithm identifier. (See `EverCrypt_Error.h`.)"] val create_in: #a:alg -> create_in_st a inline_for_extraction noextract val alloca: #a:alg -> alloca_st a /// Encryption (pre-allocated state) /// -------------------------------- inline_for_extraction noextract let iv_p a = iv:B.buffer uint8 { iv_length a (B.length iv)} inline_for_extraction noextract let ad_p a = ad:B.buffer uint8 { B.length ad <= max_length a } inline_for_extraction noextract let plain_p a = p:B.buffer uint8 { B.length p <= max_length a } inline_for_extraction noextract let cipher_p a = p:B.buffer uint8 { B.length p + tag_length a <= max_length a } // SNIPPET_START: encrypt_pre inline_for_extraction noextract let encrypt_gen_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = v iv_len = B.length iv /\ v iv_len > 0 /\ v ad_len = B.length ad /\ v ad_len <= pow2 31 /\ v plain_len = B.length plain /\ v plain_len <= max_length a /\ B.length cipher = B.length plain /\ B.length tag = tag_length a inline_for_extraction noextract let encrypt_live_disjoint_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = MB.(all_live h0 [ buf iv; buf ad; buf plain; buf cipher; buf tag ]) /\ (B.disjoint plain cipher \/ plain == cipher) /\ B.disjoint cipher tag /\ B.disjoint iv cipher /\ B.disjoint iv tag /\ B.disjoint plain tag /\ B.disjoint plain ad /\ B.disjoint ad cipher /\ B.disjoint ad tag inline_for_extraction noextract let encrypt_pre (a: supported_alg) (s:B.pointer_or_null (state_s a)) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = encrypt_gen_pre a iv iv_len ad ad_len plain plain_len cipher tag h0 /\ ( not (B.g_is_null s) ==> invariant h0 s /\ B.(loc_disjoint (footprint h0 s) (loc_buffer iv)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer ad)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer tag)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer plain)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer cipher)) /\ encrypt_live_disjoint_pre a iv iv_len ad ad_len plain plain_len cipher tag h0) // SNIPPET_END: encrypt_pre inline_for_extraction noextract let encrypt_st (a: supported_alg) = s:B.pointer_or_null (state_s a) -> iv:iv_p a -> iv_len: UInt32.t { v iv_len = B.length iv /\ v iv_len > 0 } -> ad:ad_p a -> ad_len: UInt32.t { v ad_len = B.length ad /\ v ad_len <= pow2 31 } -> plain: plain_p a -> plain_len: UInt32.t { v plain_len = B.length plain /\ v plain_len <= max_length a } -> cipher: B.buffer uint8 { B.length cipher = B.length plain } -> tag: B.buffer uint8 { B.length tag = tag_length a } -> Stack error_code (requires encrypt_pre a s iv iv_len ad ad_len plain plain_len cipher tag) (ensures fun h0 r h1 -> match r with | Success -> not (B.g_is_null s) /\ B.(modifies (loc_union (footprint h1 s) (loc_union (loc_buffer cipher) (loc_buffer tag))) h0 h1) /\ invariant h1 s /\ footprint h0 s == footprint h1 s /\ preserves_freeable s h0 h1 /\ as_kv (B.deref h1 s) == as_kv (B.deref h0 s) /\ S.equal (S.append (B.as_seq h1 cipher) (B.as_seq h1 tag)) (Spec.encrypt #a (as_kv (B.deref h0 s)) (B.as_seq h0 iv) (B.as_seq h0 ad) (B.as_seq h0 plain)) | InvalidKey -> B.g_is_null s /\ B.(modifies loc_none h0 h1) | _ -> False) /// This function takes a previously expanded key and performs encryption. /// /// Possible return values are: /// - ``Success``: encryption was successfully performed /// - ``InvalidKey``: the function was passed a NULL expanded key (see above) (** @type: true *) [@@ Comment "Encrypt and authenticate a message (`plain`) with associated data (`ad`). @param s Pointer to the The AEAD state created by `EverCrypt_AEAD_create_in`. It already contains the encryption key. @param iv Pointer to `iv_len` bytes of memory where the nonce is read from. @param iv_len Length of the nonce. Note: ChaCha20Poly1305 requires a 12 byte nonce. @param ad Pointer to `ad_len` bytes of memory where the associated data is read from. @param ad_len Length of the associated data. @param plain Pointer to `plain_len` bytes of memory where the to-be-encrypted plaintext is read from. @param plain_len Length of the to-be-encrypted plaintext. @param cipher Pointer to `plain_len` bytes of memory where the ciphertext is written to. @param tag Pointer to `TAG_LEN` bytes of memory where the tag is written to. The length of the `tag` must be of a suitable length for the chosen algorithm: * `Spec_Agile_AEAD_AES128_GCM` (TAG_LEN=16) * `Spec_Agile_AEAD_AES256_GCM` (TAG_LEN=16) * `Spec_Agile_AEAD_CHACHA20_POLY1305` (TAG_LEN=16) @return `EverCrypt_AEAD_encrypt` may return either `EverCrypt_Error_Success` or `EverCrypt_Error_InvalidKey` (`EverCrypt_error.h`). The latter is returned if and only if the `s` parameter is `NULL`."] val encrypt: #a:G.erased (supported_alg) -> encrypt_st (G.reveal a) /// Encryption (no pre-allocated state) /// ----------------------------------- /// /// All-in-one API that does not require performing key expansion separately. /// Use if you must be in the Stack effect, or if you know you do not intend to /// reuse the key with a different nonce later.
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.AEAD.supported_alg -> k: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 {LowStar.Monotonic.Buffer.length k = Spec.Agile.AEAD.key_length a} -> iv: EverCrypt.AEAD.iv_p a -> iv_len: FStar.UInt32.t -> ad: EverCrypt.AEAD.ad_p a -> ad_len: FStar.UInt32.t -> plain: EverCrypt.AEAD.plain_p a -> plain_len: FStar.UInt32.t -> cipher: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> tag: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> h0: FStar.Monotonic.HyperStack.mem -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.supported_alg", "LowStar.Buffer.buffer", "Spec.Agile.AEAD.uint8", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "Spec.Agile.AEAD.key_length", "EverCrypt.AEAD.iv_p", "FStar.UInt32.t", "EverCrypt.AEAD.ad_p", "EverCrypt.AEAD.plain_p", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverCrypt.AEAD.encrypt_gen_pre", "LowStar.Monotonic.Buffer.live", "LowStar.Monotonic.Buffer.disjoint", "EverCrypt.AEAD.encrypt_live_disjoint_pre", "Prims.logical" ]
[]
false
false
false
false
true
let encrypt_expand_pre (a: supported_alg) (k: B.buffer uint8 {B.length k = key_length a}) (iv: iv_p a) (iv_len: UInt32.t) (ad: ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher tag: B.buffer uint8) (h0: HS.mem) =
encrypt_gen_pre a iv iv_len ad ad_len plain plain_len cipher tag h0 /\ (B.live h0 k /\ B.disjoint k cipher /\ encrypt_live_disjoint_pre a iv iv_len ad ad_len plain plain_len cipher tag h0)
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.alloca_st
val alloca_st : a: Spec.Agile.AEAD.alg -> Type0
let alloca_st (a: alg) = k:B.buffer uint8 { B.length k = key_length a } -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> // Sanity invariant h1 s /\ // Memory stuff B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k)
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 44, "end_line": 197, "start_col": 0, "start_line": 181 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a) inline_for_extraction noextract let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False) /// Same function as above, but in the StackInline effect, so that it is possible /// to use AES GCM while staying in the Stack effect. In this case, the state should /// be allocated/deallocated just before/after any encryption or decryption (which /// is not very problematic during, for example, a handshake).
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.AEAD.alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.alg", "LowStar.Buffer.buffer", "Spec.Agile.AEAD.uint8", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "Spec.Agile.AEAD.key_length", "LowStar.Buffer.pointer", "EverCrypt.AEAD.state_s", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "EverCrypt.AEAD.config_pre", "Spec.Agile.AEAD.is_supported_alg", "EverCrypt.AEAD.invariant", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "LowStar.Monotonic.Buffer.fresh_loc", "EverCrypt.AEAD.footprint", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_region_only", "FStar.Monotonic.HyperStack.get_tip", "Prims.eq2", "FStar.Seq.Base.seq", "EverCrypt.AEAD.as_kv", "LowStar.Monotonic.Buffer.deref", "LowStar.Monotonic.Buffer.as_seq" ]
[]
false
false
false
true
true
let alloca_st (a: alg) =
k: B.buffer uint8 {B.length k = key_length a} -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> invariant h1 s /\ B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ as_kv (B.deref h1 s) == B.as_seq h0 k)
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.encrypt_st
val encrypt_st : a: Spec.Agile.AEAD.supported_alg -> Type0
let encrypt_st (a: supported_alg) = s:B.pointer_or_null (state_s a) -> iv:iv_p a -> iv_len: UInt32.t { v iv_len = B.length iv /\ v iv_len > 0 } -> ad:ad_p a -> ad_len: UInt32.t { v ad_len = B.length ad /\ v ad_len <= pow2 31 } -> plain: plain_p a -> plain_len: UInt32.t { v plain_len = B.length plain /\ v plain_len <= max_length a } -> cipher: B.buffer uint8 { B.length cipher = B.length plain } -> tag: B.buffer uint8 { B.length tag = tag_length a } -> Stack error_code (requires encrypt_pre a s iv iv_len ad ad_len plain plain_len cipher tag) (ensures fun h0 r h1 -> match r with | Success -> not (B.g_is_null s) /\ B.(modifies (loc_union (footprint h1 s) (loc_union (loc_buffer cipher) (loc_buffer tag))) h0 h1) /\ invariant h1 s /\ footprint h0 s == footprint h1 s /\ preserves_freeable s h0 h1 /\ as_kv (B.deref h1 s) == as_kv (B.deref h0 s) /\ S.equal (S.append (B.as_seq h1 cipher) (B.as_seq h1 tag)) (Spec.encrypt #a (as_kv (B.deref h0 s)) (B.as_seq h0 iv) (B.as_seq h0 ad) (B.as_seq h0 plain)) | InvalidKey -> B.g_is_null s /\ B.(modifies loc_none h0 h1) | _ -> False)
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 19, "end_line": 333, "start_col": 0, "start_line": 307 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a) inline_for_extraction noextract let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False) /// Same function as above, but in the StackInline effect, so that it is possible /// to use AES GCM while staying in the Stack effect. In this case, the state should /// be allocated/deallocated just before/after any encryption or decryption (which /// is not very problematic during, for example, a handshake). inline_for_extraction noextract let alloca_st (a: alg) = k:B.buffer uint8 { B.length k = key_length a } -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> // Sanity invariant h1 s /\ // Memory stuff B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k) /// This function takes a pointer to a caller-allocated reference ``dst`` then, /// if the algorithm is supported (on this platform), allocates a fresh state /// and modifies ``dst`` to point to it. The key-value associated with this can /// be obtained via ``kv (B.deref dst)``; as long as ``dst`` is not modified, /// then the caller can derive that the ``kv`` remains the same, which will be /// required for encrypt. (** @type: true *) [@@ Comment "Create the required AEAD state for the algorithm. Note: The caller must free the AEAD state by calling `EverCrypt_AEAD_free`. @param a The argument `a` must be either of: * `Spec_Agile_AEAD_AES128_GCM` (KEY_LEN=16), * `Spec_Agile_AEAD_AES256_GCM` (KEY_LEN=32), or * `Spec_Agile_AEAD_CHACHA20_POLY1305` (KEY_LEN=32). @param dst Pointer to a pointer where the address of the allocated AEAD state will be written to. @param k Pointer to `KEY_LEN` bytes of memory where the key is read from. The size depends on the used algorithm, see above. @return The function returns `EverCrypt_Error_Success` on success or `EverCrypt_Error_UnsupportedAlgorithm` in case of a bad algorithm identifier. (See `EverCrypt_Error.h`.)"] val create_in: #a:alg -> create_in_st a inline_for_extraction noextract val alloca: #a:alg -> alloca_st a /// Encryption (pre-allocated state) /// -------------------------------- inline_for_extraction noextract let iv_p a = iv:B.buffer uint8 { iv_length a (B.length iv)} inline_for_extraction noextract let ad_p a = ad:B.buffer uint8 { B.length ad <= max_length a } inline_for_extraction noextract let plain_p a = p:B.buffer uint8 { B.length p <= max_length a } inline_for_extraction noextract let cipher_p a = p:B.buffer uint8 { B.length p + tag_length a <= max_length a } // SNIPPET_START: encrypt_pre inline_for_extraction noextract let encrypt_gen_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = v iv_len = B.length iv /\ v iv_len > 0 /\ v ad_len = B.length ad /\ v ad_len <= pow2 31 /\ v plain_len = B.length plain /\ v plain_len <= max_length a /\ B.length cipher = B.length plain /\ B.length tag = tag_length a inline_for_extraction noextract let encrypt_live_disjoint_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = MB.(all_live h0 [ buf iv; buf ad; buf plain; buf cipher; buf tag ]) /\ (B.disjoint plain cipher \/ plain == cipher) /\ B.disjoint cipher tag /\ B.disjoint iv cipher /\ B.disjoint iv tag /\ B.disjoint plain tag /\ B.disjoint plain ad /\ B.disjoint ad cipher /\ B.disjoint ad tag inline_for_extraction noextract let encrypt_pre (a: supported_alg) (s:B.pointer_or_null (state_s a)) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = encrypt_gen_pre a iv iv_len ad ad_len plain plain_len cipher tag h0 /\ ( not (B.g_is_null s) ==> invariant h0 s /\ B.(loc_disjoint (footprint h0 s) (loc_buffer iv)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer ad)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer tag)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer plain)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer cipher)) /\ encrypt_live_disjoint_pre a iv iv_len ad ad_len plain plain_len cipher tag h0) // SNIPPET_END: encrypt_pre
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.AEAD.supported_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.supported_alg", "LowStar.Buffer.pointer_or_null", "EverCrypt.AEAD.state_s", "EverCrypt.AEAD.iv_p", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.Integers.within_bounds", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Integers.v", "LowStar.Monotonic.Buffer.length", "Spec.Agile.AEAD.uint8", "LowStar.Buffer.trivial_preorder", "FStar.Integers.op_Greater", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "EverCrypt.AEAD.ad_p", "FStar.Integers.op_Less_Equals", "Prims.pow2", "EverCrypt.AEAD.plain_p", "Spec.Agile.AEAD.max_length", "LowStar.Buffer.buffer", "Prims.nat", "Spec.Agile.AEAD.tag_length", "EverCrypt.Error.error_code", "EverCrypt.AEAD.encrypt_pre", "FStar.Monotonic.HyperStack.mem", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_union", "EverCrypt.AEAD.footprint", "LowStar.Monotonic.Buffer.loc_buffer", "EverCrypt.AEAD.invariant", "Prims.eq2", "LowStar.Monotonic.Buffer.loc", "EverCrypt.AEAD.preserves_freeable", "Spec.Agile.AEAD.kv", "EverCrypt.AEAD.as_kv", "LowStar.Monotonic.Buffer.deref", "FStar.Seq.Base.equal", "FStar.Seq.Base.append", "LowStar.Monotonic.Buffer.as_seq", "Spec.Agile.AEAD.encrypt", "LowStar.Monotonic.Buffer.loc_none", "Prims.l_False" ]
[]
false
false
false
true
true
let encrypt_st (a: supported_alg) =
s: B.pointer_or_null (state_s a) -> iv: iv_p a -> iv_len: UInt32.t{v iv_len = B.length iv /\ v iv_len > 0} -> ad: ad_p a -> ad_len: UInt32.t{v ad_len = B.length ad /\ v ad_len <= pow2 31} -> plain: plain_p a -> plain_len: UInt32.t{v plain_len = B.length plain /\ v plain_len <= max_length a} -> cipher: B.buffer uint8 {B.length cipher = B.length plain} -> tag: B.buffer uint8 {B.length tag = tag_length a} -> Stack error_code (requires encrypt_pre a s iv iv_len ad ad_len plain plain_len cipher tag) (ensures fun h0 r h1 -> match r with | Success -> not (B.g_is_null s) /\ B.(modifies (loc_union (footprint h1 s) (loc_union (loc_buffer cipher) (loc_buffer tag)) ) h0 h1) /\ invariant h1 s /\ footprint h0 s == footprint h1 s /\ preserves_freeable s h0 h1 /\ as_kv (B.deref h1 s) == as_kv (B.deref h0 s) /\ S.equal (S.append (B.as_seq h1 cipher) (B.as_seq h1 tag)) (Spec.encrypt #a (as_kv (B.deref h0 s)) (B.as_seq h0 iv) (B.as_seq h0 ad) (B.as_seq h0 plain)) | InvalidKey -> B.g_is_null s /\ B.(modifies loc_none h0 h1) | _ -> False)
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.encrypt_gen_pre
val encrypt_gen_pre : a: Spec.Agile.AEAD.supported_alg -> iv: EverCrypt.AEAD.iv_p a -> iv_len: FStar.UInt32.t -> ad: EverCrypt.AEAD.ad_p a -> ad_len: FStar.UInt32.t -> plain: EverCrypt.AEAD.plain_p a -> plain_len: FStar.UInt32.t -> cipher: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> tag: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> h0: FStar.Monotonic.HyperStack.mem -> Prims.logical
let encrypt_gen_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = v iv_len = B.length iv /\ v iv_len > 0 /\ v ad_len = B.length ad /\ v ad_len <= pow2 31 /\ v plain_len = B.length plain /\ v plain_len <= max_length a /\ B.length cipher = B.length plain /\ B.length tag = tag_length a
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 259, "start_col": 0, "start_line": 244 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a) inline_for_extraction noextract let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False) /// Same function as above, but in the StackInline effect, so that it is possible /// to use AES GCM while staying in the Stack effect. In this case, the state should /// be allocated/deallocated just before/after any encryption or decryption (which /// is not very problematic during, for example, a handshake). inline_for_extraction noextract let alloca_st (a: alg) = k:B.buffer uint8 { B.length k = key_length a } -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> // Sanity invariant h1 s /\ // Memory stuff B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k) /// This function takes a pointer to a caller-allocated reference ``dst`` then, /// if the algorithm is supported (on this platform), allocates a fresh state /// and modifies ``dst`` to point to it. The key-value associated with this can /// be obtained via ``kv (B.deref dst)``; as long as ``dst`` is not modified, /// then the caller can derive that the ``kv`` remains the same, which will be /// required for encrypt. (** @type: true *) [@@ Comment "Create the required AEAD state for the algorithm. Note: The caller must free the AEAD state by calling `EverCrypt_AEAD_free`. @param a The argument `a` must be either of: * `Spec_Agile_AEAD_AES128_GCM` (KEY_LEN=16), * `Spec_Agile_AEAD_AES256_GCM` (KEY_LEN=32), or * `Spec_Agile_AEAD_CHACHA20_POLY1305` (KEY_LEN=32). @param dst Pointer to a pointer where the address of the allocated AEAD state will be written to. @param k Pointer to `KEY_LEN` bytes of memory where the key is read from. The size depends on the used algorithm, see above. @return The function returns `EverCrypt_Error_Success` on success or `EverCrypt_Error_UnsupportedAlgorithm` in case of a bad algorithm identifier. (See `EverCrypt_Error.h`.)"] val create_in: #a:alg -> create_in_st a inline_for_extraction noextract val alloca: #a:alg -> alloca_st a /// Encryption (pre-allocated state) /// -------------------------------- inline_for_extraction noextract let iv_p a = iv:B.buffer uint8 { iv_length a (B.length iv)} inline_for_extraction noextract let ad_p a = ad:B.buffer uint8 { B.length ad <= max_length a } inline_for_extraction noextract let plain_p a = p:B.buffer uint8 { B.length p <= max_length a } inline_for_extraction noextract let cipher_p a = p:B.buffer uint8 { B.length p + tag_length a <= max_length a } // SNIPPET_START: encrypt_pre
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.AEAD.supported_alg -> iv: EverCrypt.AEAD.iv_p a -> iv_len: FStar.UInt32.t -> ad: EverCrypt.AEAD.ad_p a -> ad_len: FStar.UInt32.t -> plain: EverCrypt.AEAD.plain_p a -> plain_len: FStar.UInt32.t -> cipher: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> tag: LowStar.Buffer.buffer Spec.Agile.AEAD.uint8 -> h0: FStar.Monotonic.HyperStack.mem -> Prims.logical
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.supported_alg", "EverCrypt.AEAD.iv_p", "FStar.UInt32.t", "EverCrypt.AEAD.ad_p", "EverCrypt.AEAD.plain_p", "LowStar.Buffer.buffer", "Spec.Agile.AEAD.uint8", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.Integers.within_bounds", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Integers.v", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "FStar.Integers.op_Greater", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "FStar.Integers.op_Less_Equals", "Prims.pow2", "Spec.Agile.AEAD.max_length", "Prims.nat", "Spec.Agile.AEAD.tag_length", "Prims.logical" ]
[]
false
false
false
false
true
let encrypt_gen_pre (a: supported_alg) (iv: iv_p a) (iv_len: UInt32.t) (ad: ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher tag: B.buffer uint8) (h0: HS.mem) =
v iv_len = B.length iv /\ v iv_len > 0 /\ v ad_len = B.length ad /\ v ad_len <= pow2 31 /\ v plain_len = B.length plain /\ v plain_len <= max_length a /\ B.length cipher = B.length plain /\ B.length tag = tag_length a
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.decrypt_st
val decrypt_st : a: Spec.Agile.AEAD.supported_alg -> Type0
let decrypt_st (a: supported_alg) = s:B.pointer_or_null (state_s a) -> iv:iv_p a -> iv_len:UInt32.t { v iv_len = B.length iv /\ v iv_len > 0 } -> ad:ad_p a -> ad_len: UInt32.t { v ad_len = B.length ad /\ v ad_len <= pow2 31 } -> cipher: cipher_p a -> cipher_len: UInt32.t { v cipher_len = B.length cipher } -> tag: B.buffer uint8 { B.length tag = tag_length a } -> dst: B.buffer uint8 { B.length dst = B.length cipher } -> Stack error_code (requires fun h0 -> not (B.g_is_null s) ==> invariant h0 s /\ B.(loc_disjoint (footprint h0 s) (loc_buffer iv)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer ad)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer tag)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer dst)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer cipher)) /\ MB.(all_live h0 [ buf iv; buf ad; buf cipher; buf tag; buf dst ]) /\ B.disjoint tag dst /\ B.disjoint tag cipher /\ B.disjoint tag ad /\ B.disjoint cipher ad /\ B.disjoint dst ad /\ (B.disjoint cipher dst \/ cipher == dst)) (ensures fun h0 err h1 -> let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in match err with | InvalidKey -> B.g_is_null s /\ B.(modifies loc_none h0 h1) | Success -> not (B.g_is_null s) /\ ( let plain = Spec.decrypt #a (as_kv (B.deref h0 s)) (B.as_seq h0 iv) (B.as_seq h0 ad) cipher_tag in B.(modifies (loc_union (footprint h1 s) (loc_buffer dst)) h0 h1) /\ invariant h1 s /\ footprint h0 s == footprint h1 s /\ preserves_freeable s h0 h1 /\ as_kv (B.deref h1 s) == as_kv (B.deref h0 s) /\ Some? plain /\ S.equal (Some?.v plain) (B.as_seq h1 dst)) | AuthenticationFailure -> not (B.g_is_null s) /\ ( let plain = decrypt #a (as_kv (B.deref h0 s)) (B.as_seq h0 iv) (B.as_seq h0 ad) cipher_tag in B.(modifies (loc_union (footprint h1 s) (loc_buffer dst)) h0 h1) /\ invariant h1 s /\ footprint h0 s == footprint h1 s /\ preserves_freeable s h0 h1 /\ as_kv (B.deref h1 s) == as_kv (B.deref h0 s) /\ None? plain) | _ -> False)
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 502, "start_col": 0, "start_line": 453 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a) inline_for_extraction noextract let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False) /// Same function as above, but in the StackInline effect, so that it is possible /// to use AES GCM while staying in the Stack effect. In this case, the state should /// be allocated/deallocated just before/after any encryption or decryption (which /// is not very problematic during, for example, a handshake). inline_for_extraction noextract let alloca_st (a: alg) = k:B.buffer uint8 { B.length k = key_length a } -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> // Sanity invariant h1 s /\ // Memory stuff B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k) /// This function takes a pointer to a caller-allocated reference ``dst`` then, /// if the algorithm is supported (on this platform), allocates a fresh state /// and modifies ``dst`` to point to it. The key-value associated with this can /// be obtained via ``kv (B.deref dst)``; as long as ``dst`` is not modified, /// then the caller can derive that the ``kv`` remains the same, which will be /// required for encrypt. (** @type: true *) [@@ Comment "Create the required AEAD state for the algorithm. Note: The caller must free the AEAD state by calling `EverCrypt_AEAD_free`. @param a The argument `a` must be either of: * `Spec_Agile_AEAD_AES128_GCM` (KEY_LEN=16), * `Spec_Agile_AEAD_AES256_GCM` (KEY_LEN=32), or * `Spec_Agile_AEAD_CHACHA20_POLY1305` (KEY_LEN=32). @param dst Pointer to a pointer where the address of the allocated AEAD state will be written to. @param k Pointer to `KEY_LEN` bytes of memory where the key is read from. The size depends on the used algorithm, see above. @return The function returns `EverCrypt_Error_Success` on success or `EverCrypt_Error_UnsupportedAlgorithm` in case of a bad algorithm identifier. (See `EverCrypt_Error.h`.)"] val create_in: #a:alg -> create_in_st a inline_for_extraction noextract val alloca: #a:alg -> alloca_st a /// Encryption (pre-allocated state) /// -------------------------------- inline_for_extraction noextract let iv_p a = iv:B.buffer uint8 { iv_length a (B.length iv)} inline_for_extraction noextract let ad_p a = ad:B.buffer uint8 { B.length ad <= max_length a } inline_for_extraction noextract let plain_p a = p:B.buffer uint8 { B.length p <= max_length a } inline_for_extraction noextract let cipher_p a = p:B.buffer uint8 { B.length p + tag_length a <= max_length a } // SNIPPET_START: encrypt_pre inline_for_extraction noextract let encrypt_gen_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = v iv_len = B.length iv /\ v iv_len > 0 /\ v ad_len = B.length ad /\ v ad_len <= pow2 31 /\ v plain_len = B.length plain /\ v plain_len <= max_length a /\ B.length cipher = B.length plain /\ B.length tag = tag_length a inline_for_extraction noextract let encrypt_live_disjoint_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = MB.(all_live h0 [ buf iv; buf ad; buf plain; buf cipher; buf tag ]) /\ (B.disjoint plain cipher \/ plain == cipher) /\ B.disjoint cipher tag /\ B.disjoint iv cipher /\ B.disjoint iv tag /\ B.disjoint plain tag /\ B.disjoint plain ad /\ B.disjoint ad cipher /\ B.disjoint ad tag inline_for_extraction noextract let encrypt_pre (a: supported_alg) (s:B.pointer_or_null (state_s a)) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = encrypt_gen_pre a iv iv_len ad ad_len plain plain_len cipher tag h0 /\ ( not (B.g_is_null s) ==> invariant h0 s /\ B.(loc_disjoint (footprint h0 s) (loc_buffer iv)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer ad)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer tag)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer plain)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer cipher)) /\ encrypt_live_disjoint_pre a iv iv_len ad ad_len plain plain_len cipher tag h0) // SNIPPET_END: encrypt_pre inline_for_extraction noextract let encrypt_st (a: supported_alg) = s:B.pointer_or_null (state_s a) -> iv:iv_p a -> iv_len: UInt32.t { v iv_len = B.length iv /\ v iv_len > 0 } -> ad:ad_p a -> ad_len: UInt32.t { v ad_len = B.length ad /\ v ad_len <= pow2 31 } -> plain: plain_p a -> plain_len: UInt32.t { v plain_len = B.length plain /\ v plain_len <= max_length a } -> cipher: B.buffer uint8 { B.length cipher = B.length plain } -> tag: B.buffer uint8 { B.length tag = tag_length a } -> Stack error_code (requires encrypt_pre a s iv iv_len ad ad_len plain plain_len cipher tag) (ensures fun h0 r h1 -> match r with | Success -> not (B.g_is_null s) /\ B.(modifies (loc_union (footprint h1 s) (loc_union (loc_buffer cipher) (loc_buffer tag))) h0 h1) /\ invariant h1 s /\ footprint h0 s == footprint h1 s /\ preserves_freeable s h0 h1 /\ as_kv (B.deref h1 s) == as_kv (B.deref h0 s) /\ S.equal (S.append (B.as_seq h1 cipher) (B.as_seq h1 tag)) (Spec.encrypt #a (as_kv (B.deref h0 s)) (B.as_seq h0 iv) (B.as_seq h0 ad) (B.as_seq h0 plain)) | InvalidKey -> B.g_is_null s /\ B.(modifies loc_none h0 h1) | _ -> False) /// This function takes a previously expanded key and performs encryption. /// /// Possible return values are: /// - ``Success``: encryption was successfully performed /// - ``InvalidKey``: the function was passed a NULL expanded key (see above) (** @type: true *) [@@ Comment "Encrypt and authenticate a message (`plain`) with associated data (`ad`). @param s Pointer to the The AEAD state created by `EverCrypt_AEAD_create_in`. It already contains the encryption key. @param iv Pointer to `iv_len` bytes of memory where the nonce is read from. @param iv_len Length of the nonce. Note: ChaCha20Poly1305 requires a 12 byte nonce. @param ad Pointer to `ad_len` bytes of memory where the associated data is read from. @param ad_len Length of the associated data. @param plain Pointer to `plain_len` bytes of memory where the to-be-encrypted plaintext is read from. @param plain_len Length of the to-be-encrypted plaintext. @param cipher Pointer to `plain_len` bytes of memory where the ciphertext is written to. @param tag Pointer to `TAG_LEN` bytes of memory where the tag is written to. The length of the `tag` must be of a suitable length for the chosen algorithm: * `Spec_Agile_AEAD_AES128_GCM` (TAG_LEN=16) * `Spec_Agile_AEAD_AES256_GCM` (TAG_LEN=16) * `Spec_Agile_AEAD_CHACHA20_POLY1305` (TAG_LEN=16) @return `EverCrypt_AEAD_encrypt` may return either `EverCrypt_Error_Success` or `EverCrypt_Error_InvalidKey` (`EverCrypt_error.h`). The latter is returned if and only if the `s` parameter is `NULL`."] val encrypt: #a:G.erased (supported_alg) -> encrypt_st (G.reveal a) /// Encryption (no pre-allocated state) /// ----------------------------------- /// /// All-in-one API that does not require performing key expansion separately. /// Use if you must be in the Stack effect, or if you know you do not intend to /// reuse the key with a different nonce later. inline_for_extraction noextract let encrypt_expand_pre (a: supported_alg) (k:B.buffer uint8 { B.length k = key_length a }) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = encrypt_gen_pre a iv iv_len ad ad_len plain plain_len cipher tag h0 /\ ( B.live h0 k /\ B.disjoint k cipher /\ encrypt_live_disjoint_pre a iv iv_len ad ad_len plain plain_len cipher tag h0) inline_for_extraction noextract let encrypt_expand_st (does_runtime_check: bool) (a: supported_alg) = k:B.buffer uint8 { B.length k = key_length a } -> iv:iv_p a -> iv_len: UInt32.t { v iv_len = B.length iv /\ v iv_len > 0 } -> ad:ad_p a -> ad_len: UInt32.t { v ad_len = B.length ad /\ v ad_len <= pow2 31 } -> plain: plain_p a -> plain_len: UInt32.t { v plain_len = B.length plain /\ v plain_len <= max_length a } -> cipher: B.buffer uint8 { B.length cipher = B.length plain } -> tag: B.buffer uint8 { B.length tag = tag_length a } -> Stack error_code (requires fun h0 -> (if does_runtime_check then True else config_pre a) /\ encrypt_expand_pre a k iv iv_len ad ad_len plain plain_len cipher tag h0) (ensures fun h0 r h1 -> match r with | Success -> B.(modifies ((loc_union (loc_buffer cipher) (loc_buffer tag))) h0 h1) /\ S.equal (S.append (B.as_seq h1 cipher) (B.as_seq h1 tag)) (Spec.encrypt #a (B.as_seq h0 k) (B.as_seq h0 iv) (B.as_seq h0 ad) (B.as_seq h0 plain)) | UnsupportedAlgorithm -> if does_runtime_check then B.(modifies loc_none h0 h1) else False | _ -> False) /// It's a little difficult to deal with AES-GCM cleanly because we're missing a /// fallback C implementation. The two functions below guard the reference to the /// X64 AES-GCM code behind a test of `EverCrypt.TargetConfig.hacl_can_compile_vale`, /// which gets extracted to a preprocessor test, so that we can always compile them. /// In case the code is compiled on a system which doesn't support Vale, the functions /// are compiled in such a way that they make the program exit cleanly. [@@ Comment "WARNING: this function doesn't perform any dynamic hardware check. You MUST make sure your hardware supports the implementation of AESGCM. Besides, this function was not designed for cross-compilation: if you compile it on a system which doesn't support Vale, it will compile it to a function which makes the program exit."] val encrypt_expand_aes128_gcm_no_check: encrypt_expand_st false AES128_GCM [@@ Comment "WARNING: this function doesn't perform any dynamic hardware check. You MUST make sure your hardware supports the implementation of AESGCM. Besides, this function was not designed for cross-compilation: if you compile it on a system which doesn't support Vale, it will compile it to a function which makes the program exit."] val encrypt_expand_aes256_gcm_no_check: encrypt_expand_st false AES256_GCM /// Those functions take a key, expand it then perform encryption. They do not /// require calling create_in before. val encrypt_expand_aes128_gcm: encrypt_expand_st true AES128_GCM val encrypt_expand_aes256_gcm: encrypt_expand_st true AES256_GCM val encrypt_expand_chacha20_poly1305: encrypt_expand_st false CHACHA20_POLY1305 /// Run-time agility, run-time multiplexing, but not pre-expansion of the key. val encrypt_expand: #a:supported_alg -> encrypt_expand_st true (G.reveal a) /// Decryption (pre-allocated state) /// --------------------------------
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.AEAD.supported_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.AEAD.supported_alg", "LowStar.Buffer.pointer_or_null", "EverCrypt.AEAD.state_s", "EverCrypt.AEAD.iv_p", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.Integers.within_bounds", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Integers.v", "LowStar.Monotonic.Buffer.length", "Spec.Agile.AEAD.uint8", "LowStar.Buffer.trivial_preorder", "FStar.Integers.op_Greater", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "EverCrypt.AEAD.ad_p", "FStar.Integers.op_Less_Equals", "Prims.pow2", "EverCrypt.AEAD.cipher_p", "LowStar.Buffer.buffer", "Spec.Agile.AEAD.tag_length", "Prims.nat", "EverCrypt.Error.error_code", "FStar.Monotonic.HyperStack.mem", "Prims.l_imp", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "EverCrypt.AEAD.invariant", "LowStar.Monotonic.Buffer.loc_disjoint", "EverCrypt.AEAD.footprint", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Monotonic.Buffer.all_live", "Prims.Cons", "LowStar.Monotonic.Buffer.buf_t", "LowStar.Monotonic.Buffer.buf", "Prims.Nil", "LowStar.Monotonic.Buffer.disjoint", "Prims.eq2", "FStar.Integers.op_Plus", "Spec.Agile.AEAD.max_length", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc", "EverCrypt.AEAD.preserves_freeable", "Spec.Agile.AEAD.kv", "EverCrypt.AEAD.as_kv", "LowStar.Monotonic.Buffer.deref", "FStar.Pervasives.Native.uu___is_Some", "Spec.Agile.AEAD.decrypted", "FStar.Seq.Base.equal", "FStar.Pervasives.Native.__proj__Some__item__v", "LowStar.Monotonic.Buffer.as_seq", "FStar.Pervasives.Native.option", "Spec.Agile.AEAD.decrypt", "FStar.Pervasives.Native.uu___is_None", "Prims.l_False", "FStar.Seq.Base.seq", "FStar.Seq.Base.append" ]
[]
false
false
false
true
true
let decrypt_st (a: supported_alg) =
s: B.pointer_or_null (state_s a) -> iv: iv_p a -> iv_len: UInt32.t{v iv_len = B.length iv /\ v iv_len > 0} -> ad: ad_p a -> ad_len: UInt32.t{v ad_len = B.length ad /\ v ad_len <= pow2 31} -> cipher: cipher_p a -> cipher_len: UInt32.t{v cipher_len = B.length cipher} -> tag: B.buffer uint8 {B.length tag = tag_length a} -> dst: B.buffer uint8 {B.length dst = B.length cipher} -> Stack error_code (requires fun h0 -> not (B.g_is_null s) ==> invariant h0 s /\ B.(loc_disjoint (footprint h0 s) (loc_buffer iv)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer ad)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer tag)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer dst)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer cipher)) /\ MB.(all_live h0 [buf iv; buf ad; buf cipher; buf tag; buf dst]) /\ B.disjoint tag dst /\ B.disjoint tag cipher /\ B.disjoint tag ad /\ B.disjoint cipher ad /\ B.disjoint dst ad /\ (B.disjoint cipher dst \/ cipher == dst)) (ensures fun h0 err h1 -> let cipher_tag = (B.as_seq h0 cipher) `S.append` (B.as_seq h0 tag) in match err with | InvalidKey -> B.g_is_null s /\ B.(modifies loc_none h0 h1) | Success -> not (B.g_is_null s) /\ (let plain = Spec.decrypt #a (as_kv (B.deref h0 s)) (B.as_seq h0 iv) (B.as_seq h0 ad) cipher_tag in B.(modifies (loc_union (footprint h1 s) (loc_buffer dst)) h0 h1) /\ invariant h1 s /\ footprint h0 s == footprint h1 s /\ preserves_freeable s h0 h1 /\ as_kv (B.deref h1 s) == as_kv (B.deref h0 s) /\ Some? plain /\ S.equal (Some?.v plain) (B.as_seq h1 dst)) | AuthenticationFailure -> not (B.g_is_null s) /\ (let plain = decrypt #a (as_kv (B.deref h0 s)) (B.as_seq h0 iv) (B.as_seq h0 ad) cipher_tag in B.(modifies (loc_union (footprint h1 s) (loc_buffer dst)) h0 h1) /\ invariant h1 s /\ footprint h0 s == footprint h1 s /\ preserves_freeable s h0 h1 /\ as_kv (B.deref h1 s) == as_kv (B.deref h0 s) /\ None? plain) | _ -> False)
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.encrypt_expand_st
val encrypt_expand_st : does_runtime_check: Prims.bool -> a: Spec.Agile.AEAD.supported_alg -> Type0
let encrypt_expand_st (does_runtime_check: bool) (a: supported_alg) = k:B.buffer uint8 { B.length k = key_length a } -> iv:iv_p a -> iv_len: UInt32.t { v iv_len = B.length iv /\ v iv_len > 0 } -> ad:ad_p a -> ad_len: UInt32.t { v ad_len = B.length ad /\ v ad_len <= pow2 31 } -> plain: plain_p a -> plain_len: UInt32.t { v plain_len = B.length plain /\ v plain_len <= max_length a } -> cipher: B.buffer uint8 { B.length cipher = B.length plain } -> tag: B.buffer uint8 { B.length tag = tag_length a } -> Stack error_code (requires fun h0 -> (if does_runtime_check then True else config_pre a) /\ encrypt_expand_pre a k iv iv_len ad ad_len plain plain_len cipher tag h0) (ensures fun h0 r h1 -> match r with | Success -> B.(modifies ((loc_union (loc_buffer cipher) (loc_buffer tag))) h0 h1) /\ S.equal (S.append (B.as_seq h1 cipher) (B.as_seq h1 tag)) (Spec.encrypt #a (B.as_seq h0 k) (B.as_seq h0 iv) (B.as_seq h0 ad) (B.as_seq h0 plain)) | UnsupportedAlgorithm -> if does_runtime_check then B.(modifies loc_none h0 h1) else False | _ -> False)
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 16, "end_line": 415, "start_col": 0, "start_line": 386 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a) inline_for_extraction noextract let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False) /// Same function as above, but in the StackInline effect, so that it is possible /// to use AES GCM while staying in the Stack effect. In this case, the state should /// be allocated/deallocated just before/after any encryption or decryption (which /// is not very problematic during, for example, a handshake). inline_for_extraction noextract let alloca_st (a: alg) = k:B.buffer uint8 { B.length k = key_length a } -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> // Sanity invariant h1 s /\ // Memory stuff B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k) /// This function takes a pointer to a caller-allocated reference ``dst`` then, /// if the algorithm is supported (on this platform), allocates a fresh state /// and modifies ``dst`` to point to it. The key-value associated with this can /// be obtained via ``kv (B.deref dst)``; as long as ``dst`` is not modified, /// then the caller can derive that the ``kv`` remains the same, which will be /// required for encrypt. (** @type: true *) [@@ Comment "Create the required AEAD state for the algorithm. Note: The caller must free the AEAD state by calling `EverCrypt_AEAD_free`. @param a The argument `a` must be either of: * `Spec_Agile_AEAD_AES128_GCM` (KEY_LEN=16), * `Spec_Agile_AEAD_AES256_GCM` (KEY_LEN=32), or * `Spec_Agile_AEAD_CHACHA20_POLY1305` (KEY_LEN=32). @param dst Pointer to a pointer where the address of the allocated AEAD state will be written to. @param k Pointer to `KEY_LEN` bytes of memory where the key is read from. The size depends on the used algorithm, see above. @return The function returns `EverCrypt_Error_Success` on success or `EverCrypt_Error_UnsupportedAlgorithm` in case of a bad algorithm identifier. (See `EverCrypt_Error.h`.)"] val create_in: #a:alg -> create_in_st a inline_for_extraction noextract val alloca: #a:alg -> alloca_st a /// Encryption (pre-allocated state) /// -------------------------------- inline_for_extraction noextract let iv_p a = iv:B.buffer uint8 { iv_length a (B.length iv)} inline_for_extraction noextract let ad_p a = ad:B.buffer uint8 { B.length ad <= max_length a } inline_for_extraction noextract let plain_p a = p:B.buffer uint8 { B.length p <= max_length a } inline_for_extraction noextract let cipher_p a = p:B.buffer uint8 { B.length p + tag_length a <= max_length a } // SNIPPET_START: encrypt_pre inline_for_extraction noextract let encrypt_gen_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = v iv_len = B.length iv /\ v iv_len > 0 /\ v ad_len = B.length ad /\ v ad_len <= pow2 31 /\ v plain_len = B.length plain /\ v plain_len <= max_length a /\ B.length cipher = B.length plain /\ B.length tag = tag_length a inline_for_extraction noextract let encrypt_live_disjoint_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = MB.(all_live h0 [ buf iv; buf ad; buf plain; buf cipher; buf tag ]) /\ (B.disjoint plain cipher \/ plain == cipher) /\ B.disjoint cipher tag /\ B.disjoint iv cipher /\ B.disjoint iv tag /\ B.disjoint plain tag /\ B.disjoint plain ad /\ B.disjoint ad cipher /\ B.disjoint ad tag inline_for_extraction noextract let encrypt_pre (a: supported_alg) (s:B.pointer_or_null (state_s a)) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = encrypt_gen_pre a iv iv_len ad ad_len plain plain_len cipher tag h0 /\ ( not (B.g_is_null s) ==> invariant h0 s /\ B.(loc_disjoint (footprint h0 s) (loc_buffer iv)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer ad)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer tag)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer plain)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer cipher)) /\ encrypt_live_disjoint_pre a iv iv_len ad ad_len plain plain_len cipher tag h0) // SNIPPET_END: encrypt_pre inline_for_extraction noextract let encrypt_st (a: supported_alg) = s:B.pointer_or_null (state_s a) -> iv:iv_p a -> iv_len: UInt32.t { v iv_len = B.length iv /\ v iv_len > 0 } -> ad:ad_p a -> ad_len: UInt32.t { v ad_len = B.length ad /\ v ad_len <= pow2 31 } -> plain: plain_p a -> plain_len: UInt32.t { v plain_len = B.length plain /\ v plain_len <= max_length a } -> cipher: B.buffer uint8 { B.length cipher = B.length plain } -> tag: B.buffer uint8 { B.length tag = tag_length a } -> Stack error_code (requires encrypt_pre a s iv iv_len ad ad_len plain plain_len cipher tag) (ensures fun h0 r h1 -> match r with | Success -> not (B.g_is_null s) /\ B.(modifies (loc_union (footprint h1 s) (loc_union (loc_buffer cipher) (loc_buffer tag))) h0 h1) /\ invariant h1 s /\ footprint h0 s == footprint h1 s /\ preserves_freeable s h0 h1 /\ as_kv (B.deref h1 s) == as_kv (B.deref h0 s) /\ S.equal (S.append (B.as_seq h1 cipher) (B.as_seq h1 tag)) (Spec.encrypt #a (as_kv (B.deref h0 s)) (B.as_seq h0 iv) (B.as_seq h0 ad) (B.as_seq h0 plain)) | InvalidKey -> B.g_is_null s /\ B.(modifies loc_none h0 h1) | _ -> False) /// This function takes a previously expanded key and performs encryption. /// /// Possible return values are: /// - ``Success``: encryption was successfully performed /// - ``InvalidKey``: the function was passed a NULL expanded key (see above) (** @type: true *) [@@ Comment "Encrypt and authenticate a message (`plain`) with associated data (`ad`). @param s Pointer to the The AEAD state created by `EverCrypt_AEAD_create_in`. It already contains the encryption key. @param iv Pointer to `iv_len` bytes of memory where the nonce is read from. @param iv_len Length of the nonce. Note: ChaCha20Poly1305 requires a 12 byte nonce. @param ad Pointer to `ad_len` bytes of memory where the associated data is read from. @param ad_len Length of the associated data. @param plain Pointer to `plain_len` bytes of memory where the to-be-encrypted plaintext is read from. @param plain_len Length of the to-be-encrypted plaintext. @param cipher Pointer to `plain_len` bytes of memory where the ciphertext is written to. @param tag Pointer to `TAG_LEN` bytes of memory where the tag is written to. The length of the `tag` must be of a suitable length for the chosen algorithm: * `Spec_Agile_AEAD_AES128_GCM` (TAG_LEN=16) * `Spec_Agile_AEAD_AES256_GCM` (TAG_LEN=16) * `Spec_Agile_AEAD_CHACHA20_POLY1305` (TAG_LEN=16) @return `EverCrypt_AEAD_encrypt` may return either `EverCrypt_Error_Success` or `EverCrypt_Error_InvalidKey` (`EverCrypt_error.h`). The latter is returned if and only if the `s` parameter is `NULL`."] val encrypt: #a:G.erased (supported_alg) -> encrypt_st (G.reveal a) /// Encryption (no pre-allocated state) /// ----------------------------------- /// /// All-in-one API that does not require performing key expansion separately. /// Use if you must be in the Stack effect, or if you know you do not intend to /// reuse the key with a different nonce later. inline_for_extraction noextract let encrypt_expand_pre (a: supported_alg) (k:B.buffer uint8 { B.length k = key_length a }) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = encrypt_gen_pre a iv iv_len ad ad_len plain plain_len cipher tag h0 /\ ( B.live h0 k /\ B.disjoint k cipher /\ encrypt_live_disjoint_pre a iv iv_len ad ad_len plain plain_len cipher tag h0)
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
does_runtime_check: Prims.bool -> a: Spec.Agile.AEAD.supported_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Spec.Agile.AEAD.supported_alg", "LowStar.Buffer.buffer", "Spec.Agile.AEAD.uint8", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "Spec.Agile.AEAD.key_length", "EverCrypt.AEAD.iv_p", "FStar.UInt32.t", "Prims.l_and", "FStar.Integers.within_bounds", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Integers.v", "FStar.Integers.op_Greater", "EverCrypt.AEAD.ad_p", "FStar.Integers.op_Less_Equals", "Prims.pow2", "EverCrypt.AEAD.plain_p", "Spec.Agile.AEAD.max_length", "Prims.nat", "Spec.Agile.AEAD.tag_length", "EverCrypt.Error.error_code", "FStar.Monotonic.HyperStack.mem", "Prims.l_True", "EverCrypt.AEAD.config_pre", "Prims.logical", "EverCrypt.AEAD.encrypt_expand_pre", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "FStar.Seq.Base.equal", "FStar.Seq.Base.append", "LowStar.Monotonic.Buffer.as_seq", "Spec.Agile.AEAD.encrypt", "LowStar.Monotonic.Buffer.loc_none", "Prims.l_False" ]
[]
false
false
false
true
true
let encrypt_expand_st (does_runtime_check: bool) (a: supported_alg) =
k: B.buffer uint8 {B.length k = key_length a} -> iv: iv_p a -> iv_len: UInt32.t{v iv_len = B.length iv /\ v iv_len > 0} -> ad: ad_p a -> ad_len: UInt32.t{v ad_len = B.length ad /\ v ad_len <= pow2 31} -> plain: plain_p a -> plain_len: UInt32.t{v plain_len = B.length plain /\ v plain_len <= max_length a} -> cipher: B.buffer uint8 {B.length cipher = B.length plain} -> tag: B.buffer uint8 {B.length tag = tag_length a} -> Stack error_code (requires fun h0 -> (if does_runtime_check then True else config_pre a) /\ encrypt_expand_pre a k iv iv_len ad ad_len plain plain_len cipher tag h0) (ensures fun h0 r h1 -> match r with | Success -> B.(modifies ((loc_union (loc_buffer cipher) (loc_buffer tag))) h0 h1) /\ S.equal (S.append (B.as_seq h1 cipher) (B.as_seq h1 tag)) (Spec.encrypt #a (B.as_seq h0 k) (B.as_seq h0 iv) (B.as_seq h0 ad) (B.as_seq h0 plain) ) | UnsupportedAlgorithm -> if does_runtime_check then let open B in modifies loc_none h0 h1 else False | _ -> False)
false
EverCrypt.AEAD.fsti
EverCrypt.AEAD.decrypt_expand_st
val decrypt_expand_st : does_runtime_check: Prims.bool -> a: Spec.Agile.AEAD.supported_alg -> Type0
let decrypt_expand_st (does_runtime_check: bool) (a: supported_alg) = k:B.buffer uint8 { B.length k = key_length a } -> iv:iv_p a -> iv_len:UInt32.t { v iv_len = B.length iv /\ v iv_len > 0 } -> ad:ad_p a -> ad_len: UInt32.t { v ad_len = B.length ad /\ v ad_len <= pow2 31 } -> cipher: cipher_p a -> cipher_len: UInt32.t { v cipher_len = B.length cipher } -> tag: B.buffer uint8 { B.length tag = tag_length a } -> dst: B.buffer uint8 { B.length dst = B.length cipher } -> Stack error_code (requires fun h0 -> (if does_runtime_check then True else config_pre a) /\ MB.(all_live h0 [ buf k; buf iv; buf ad; buf cipher; buf tag; buf dst ]) /\ B.disjoint k dst /\ B.disjoint tag dst /\ B.disjoint tag cipher /\ B.disjoint tag ad /\ B.disjoint cipher ad /\ B.disjoint dst ad /\ (B.disjoint cipher dst \/ cipher == dst)) (ensures fun h0 err h1 -> let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in let plain = Spec.decrypt #a (B.as_seq h0 k) (B.as_seq h0 iv) (B.as_seq h0 ad) cipher_tag in B.(modifies (loc_buffer dst) h0 h1) /\ begin match err with | Success -> Some? plain /\ S.equal (Some?.v plain) (B.as_seq h1 dst) | AuthenticationFailure -> None? plain | UnsupportedAlgorithm -> if does_runtime_check then B.(modifies loc_none h0 h1) else False | _ -> False end)
{ "file_name": "providers/evercrypt/EverCrypt.AEAD.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 10, "end_line": 586, "start_col": 0, "start_line": 548 }
module EverCrypt.AEAD /// The new AEAD interface for EverCrypt, which supersedes the functions found /// in EverCrypt.fst /// /// The expected usage for this module is as follows: /// - client expands key, obtaining an ``expanded_key a`` /// - client uses ``encrypt``/``decrypt`` with the same ``expanded_key a`` repeatedly. /// /// This usage protocol is enforced for verified F* clients but, naturally, /// isn't for C clients. module S = FStar.Seq module G = FStar.Ghost module HS = FStar.HyperStack module ST = FStar.HyperStack.ST module MB = LowStar.Monotonic.Buffer module B = LowStar.Buffer open FStar.HyperStack.ST open FStar.Integers open Spec.Agile.AEAD module Spec = Spec.Agile.AEAD open EverCrypt.Error /// Note: if the fst and the fsti are running on different fuel settings, /// something that works in the interactive mode for the fsti, when /// "re-interpreted" in the fst, might stop working! #set-options "--max_fuel 0 --max_ifuel 0" /// Abstract footprints, with the same machinery as EverCrypt.Hash /// -------------------------------------------------------------- /// /// Differences from EverCrypt.Hash include: combined framing lemma, the /// equivalent of the ``repr`` function does *not* require the memory, and order /// of arguments to be in line with ``B.as_seq``, etc. which take the memory /// first. [@@ CAbstractStruct; Comment "Both encryption and decryption require a state that holds the key. The state may be reused as many times as desired."] val state_s: alg -> Type0 inline_for_extraction noextract let state alg = B.pointer (state_s alg) inline_for_extraction noextract val freeable_s: #(a: alg) -> state_s a -> Type0 inline_for_extraction noextract let freeable (#a: alg) (h: HS.mem) (p: state a) = B.freeable p /\ freeable_s (B.deref h p) inline_for_extraction noextract let preserves_freeable #a (s: state a) (h0 h1: HS.mem): Type0 = freeable h0 s ==> freeable h1 s val footprint_s: #a:alg -> state_s a -> GTot B.loc let footprint (#a:alg) (m: HS.mem) (s: state a) = B.(loc_union (loc_addr_of_buffer s) (footprint_s (B.deref m s))) // TR: the following pattern is necessary because, if we generically // add such a pattern directly on `loc_includes_union_l`, then // verification will blowup whenever both sides of `loc_includes` are // `loc_union`s. We would like to break all unions on the // right-hand-side of `loc_includes` first, using // `loc_includes_union_r`. Here the pattern is on `footprint_s`, // because we already expose the fact that `footprint` is a // `loc_union`. (In other words, the pattern should be on every // smallest location that is not exposed to be a `loc_union`.) let loc_includes_union_l_footprint_s (l1 l2: B.loc) (#a: alg) (s: state_s a) : Lemma (requires ( B.loc_includes l1 (footprint_s s) \/ B.loc_includes l2 (footprint_s s) )) (ensures (B.loc_includes (B.loc_union l1 l2) (footprint_s s))) [SMTPat (B.loc_includes (B.loc_union l1 l2) (footprint_s s))] = B.loc_includes_union_l l1 l2 (footprint_s s) /// The configuration preconditions inline_for_extraction noextract let config_pre a = match a with | AES128_GCM | AES256_GCM -> EverCrypt.TargetConfig.hacl_can_compile_vale /\ Vale.X64.CPU_Features_s.(aesni_enabled /\ pclmulqdq_enabled /\ avx_enabled /\ movbe_enabled /\ sse_enabled) | CHACHA20_POLY1305 -> True | _ -> True inline_for_extraction noextract val invariant_s: (#a:alg) -> HS.mem -> state_s a -> Type0 inline_for_extraction noextract let invariant (#a:alg) (m: HS.mem) (s: state a) = B.live m s /\ B.(loc_disjoint (loc_addr_of_buffer s) (footprint_s (B.deref m s))) /\ invariant_s m (B.get m s 0) val invariant_loc_in_footprint (#a: alg) (s: state a) (m: HS.mem) : Lemma (requires (invariant m s)) (ensures (B.loc_in (footprint m s) m)) [SMTPat (invariant m s)] val frame_invariant: #a:alg -> l:B.loc -> s:state a -> h0:HS.mem -> h1:HS.mem -> Lemma (requires ( invariant h0 s /\ B.loc_disjoint l (footprint h0 s) /\ B.modifies l h0 h1)) (ensures ( invariant h1 s /\ footprint h0 s == footprint h1 s)) [ SMTPat (invariant h1 s); SMTPat (B.modifies l h0 h1) ] /// Actual stateful API /// ------------------- noextract let bytes = Seq.seq uint8 [@@ Comment "Return the algorithm used in the AEAD state. @param s State of the AEAD algorithm. @return Algorithm used in the AEAD state."] val alg_of_state (a: G.erased alg) (s: state (G.reveal a)): Stack alg (requires (fun h0 -> invariant #(G.reveal a) h0 s)) (ensures (fun h0 a' h1 -> a' == G.reveal a /\ h0 == h1)) /// The API is constructed in a way that one can always get the original key /// value behind a state, any any memory. val as_kv: (#a: alg) -> state_s a -> GTot (kv a) inline_for_extraction noextract let create_in_st (a: alg) = r:HS.rid -> dst:B.pointer (B.pointer_or_null (state_s a)) -> k:B.buffer uint8 { B.length k = key_length a } -> ST error_code (requires fun h0 -> ST.is_eternal_region r /\ B.live h0 k /\ B.live h0 dst) (ensures fun h0 e h1 -> match e with | UnsupportedAlgorithm -> B.(modifies loc_none h0 h1) | Success -> let s = B.deref h1 dst in // Sanity is_supported_alg a /\ not (B.g_is_null s) /\ invariant h1 s /\ // Memory stuff B.(modifies (loc_buffer dst) h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.(loc_includes (loc_region_only true r) (footprint h1 s)) /\ freeable h1 s /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k | _ -> False) /// Same function as above, but in the StackInline effect, so that it is possible /// to use AES GCM while staying in the Stack effect. In this case, the state should /// be allocated/deallocated just before/after any encryption or decryption (which /// is not very problematic during, for example, a handshake). inline_for_extraction noextract let alloca_st (a: alg) = k:B.buffer uint8 { B.length k = key_length a } -> StackInline (B.pointer (state_s a)) (requires fun h0 -> B.live h0 k /\ config_pre a /\ is_supported_alg a) (ensures fun h0 s h1 -> // Sanity invariant h1 s /\ // Memory stuff B.(modifies loc_none h0 h1) /\ B.fresh_loc (footprint h1 s) h0 h1 /\ B.live h1 s /\ B.(loc_includes (loc_region_only true (HS.get_tip h1)) (footprint h1 s)) /\ // Useful stuff as_kv (B.deref h1 s) == B.as_seq h0 k) /// This function takes a pointer to a caller-allocated reference ``dst`` then, /// if the algorithm is supported (on this platform), allocates a fresh state /// and modifies ``dst`` to point to it. The key-value associated with this can /// be obtained via ``kv (B.deref dst)``; as long as ``dst`` is not modified, /// then the caller can derive that the ``kv`` remains the same, which will be /// required for encrypt. (** @type: true *) [@@ Comment "Create the required AEAD state for the algorithm. Note: The caller must free the AEAD state by calling `EverCrypt_AEAD_free`. @param a The argument `a` must be either of: * `Spec_Agile_AEAD_AES128_GCM` (KEY_LEN=16), * `Spec_Agile_AEAD_AES256_GCM` (KEY_LEN=32), or * `Spec_Agile_AEAD_CHACHA20_POLY1305` (KEY_LEN=32). @param dst Pointer to a pointer where the address of the allocated AEAD state will be written to. @param k Pointer to `KEY_LEN` bytes of memory where the key is read from. The size depends on the used algorithm, see above. @return The function returns `EverCrypt_Error_Success` on success or `EverCrypt_Error_UnsupportedAlgorithm` in case of a bad algorithm identifier. (See `EverCrypt_Error.h`.)"] val create_in: #a:alg -> create_in_st a inline_for_extraction noextract val alloca: #a:alg -> alloca_st a /// Encryption (pre-allocated state) /// -------------------------------- inline_for_extraction noextract let iv_p a = iv:B.buffer uint8 { iv_length a (B.length iv)} inline_for_extraction noextract let ad_p a = ad:B.buffer uint8 { B.length ad <= max_length a } inline_for_extraction noextract let plain_p a = p:B.buffer uint8 { B.length p <= max_length a } inline_for_extraction noextract let cipher_p a = p:B.buffer uint8 { B.length p + tag_length a <= max_length a } // SNIPPET_START: encrypt_pre inline_for_extraction noextract let encrypt_gen_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = v iv_len = B.length iv /\ v iv_len > 0 /\ v ad_len = B.length ad /\ v ad_len <= pow2 31 /\ v plain_len = B.length plain /\ v plain_len <= max_length a /\ B.length cipher = B.length plain /\ B.length tag = tag_length a inline_for_extraction noextract let encrypt_live_disjoint_pre (a: supported_alg) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = MB.(all_live h0 [ buf iv; buf ad; buf plain; buf cipher; buf tag ]) /\ (B.disjoint plain cipher \/ plain == cipher) /\ B.disjoint cipher tag /\ B.disjoint iv cipher /\ B.disjoint iv tag /\ B.disjoint plain tag /\ B.disjoint plain ad /\ B.disjoint ad cipher /\ B.disjoint ad tag inline_for_extraction noextract let encrypt_pre (a: supported_alg) (s:B.pointer_or_null (state_s a)) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = encrypt_gen_pre a iv iv_len ad ad_len plain plain_len cipher tag h0 /\ ( not (B.g_is_null s) ==> invariant h0 s /\ B.(loc_disjoint (footprint h0 s) (loc_buffer iv)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer ad)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer tag)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer plain)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer cipher)) /\ encrypt_live_disjoint_pre a iv iv_len ad ad_len plain plain_len cipher tag h0) // SNIPPET_END: encrypt_pre inline_for_extraction noextract let encrypt_st (a: supported_alg) = s:B.pointer_or_null (state_s a) -> iv:iv_p a -> iv_len: UInt32.t { v iv_len = B.length iv /\ v iv_len > 0 } -> ad:ad_p a -> ad_len: UInt32.t { v ad_len = B.length ad /\ v ad_len <= pow2 31 } -> plain: plain_p a -> plain_len: UInt32.t { v plain_len = B.length plain /\ v plain_len <= max_length a } -> cipher: B.buffer uint8 { B.length cipher = B.length plain } -> tag: B.buffer uint8 { B.length tag = tag_length a } -> Stack error_code (requires encrypt_pre a s iv iv_len ad ad_len plain plain_len cipher tag) (ensures fun h0 r h1 -> match r with | Success -> not (B.g_is_null s) /\ B.(modifies (loc_union (footprint h1 s) (loc_union (loc_buffer cipher) (loc_buffer tag))) h0 h1) /\ invariant h1 s /\ footprint h0 s == footprint h1 s /\ preserves_freeable s h0 h1 /\ as_kv (B.deref h1 s) == as_kv (B.deref h0 s) /\ S.equal (S.append (B.as_seq h1 cipher) (B.as_seq h1 tag)) (Spec.encrypt #a (as_kv (B.deref h0 s)) (B.as_seq h0 iv) (B.as_seq h0 ad) (B.as_seq h0 plain)) | InvalidKey -> B.g_is_null s /\ B.(modifies loc_none h0 h1) | _ -> False) /// This function takes a previously expanded key and performs encryption. /// /// Possible return values are: /// - ``Success``: encryption was successfully performed /// - ``InvalidKey``: the function was passed a NULL expanded key (see above) (** @type: true *) [@@ Comment "Encrypt and authenticate a message (`plain`) with associated data (`ad`). @param s Pointer to the The AEAD state created by `EverCrypt_AEAD_create_in`. It already contains the encryption key. @param iv Pointer to `iv_len` bytes of memory where the nonce is read from. @param iv_len Length of the nonce. Note: ChaCha20Poly1305 requires a 12 byte nonce. @param ad Pointer to `ad_len` bytes of memory where the associated data is read from. @param ad_len Length of the associated data. @param plain Pointer to `plain_len` bytes of memory where the to-be-encrypted plaintext is read from. @param plain_len Length of the to-be-encrypted plaintext. @param cipher Pointer to `plain_len` bytes of memory where the ciphertext is written to. @param tag Pointer to `TAG_LEN` bytes of memory where the tag is written to. The length of the `tag` must be of a suitable length for the chosen algorithm: * `Spec_Agile_AEAD_AES128_GCM` (TAG_LEN=16) * `Spec_Agile_AEAD_AES256_GCM` (TAG_LEN=16) * `Spec_Agile_AEAD_CHACHA20_POLY1305` (TAG_LEN=16) @return `EverCrypt_AEAD_encrypt` may return either `EverCrypt_Error_Success` or `EverCrypt_Error_InvalidKey` (`EverCrypt_error.h`). The latter is returned if and only if the `s` parameter is `NULL`."] val encrypt: #a:G.erased (supported_alg) -> encrypt_st (G.reveal a) /// Encryption (no pre-allocated state) /// ----------------------------------- /// /// All-in-one API that does not require performing key expansion separately. /// Use if you must be in the Stack effect, or if you know you do not intend to /// reuse the key with a different nonce later. inline_for_extraction noextract let encrypt_expand_pre (a: supported_alg) (k:B.buffer uint8 { B.length k = key_length a }) (iv:iv_p a) (iv_len: UInt32.t) (ad:ad_p a) (ad_len: UInt32.t) (plain: plain_p a) (plain_len: UInt32.t) (cipher: B.buffer uint8) (tag: B.buffer uint8) (h0: HS.mem) = encrypt_gen_pre a iv iv_len ad ad_len plain plain_len cipher tag h0 /\ ( B.live h0 k /\ B.disjoint k cipher /\ encrypt_live_disjoint_pre a iv iv_len ad ad_len plain plain_len cipher tag h0) inline_for_extraction noextract let encrypt_expand_st (does_runtime_check: bool) (a: supported_alg) = k:B.buffer uint8 { B.length k = key_length a } -> iv:iv_p a -> iv_len: UInt32.t { v iv_len = B.length iv /\ v iv_len > 0 } -> ad:ad_p a -> ad_len: UInt32.t { v ad_len = B.length ad /\ v ad_len <= pow2 31 } -> plain: plain_p a -> plain_len: UInt32.t { v plain_len = B.length plain /\ v plain_len <= max_length a } -> cipher: B.buffer uint8 { B.length cipher = B.length plain } -> tag: B.buffer uint8 { B.length tag = tag_length a } -> Stack error_code (requires fun h0 -> (if does_runtime_check then True else config_pre a) /\ encrypt_expand_pre a k iv iv_len ad ad_len plain plain_len cipher tag h0) (ensures fun h0 r h1 -> match r with | Success -> B.(modifies ((loc_union (loc_buffer cipher) (loc_buffer tag))) h0 h1) /\ S.equal (S.append (B.as_seq h1 cipher) (B.as_seq h1 tag)) (Spec.encrypt #a (B.as_seq h0 k) (B.as_seq h0 iv) (B.as_seq h0 ad) (B.as_seq h0 plain)) | UnsupportedAlgorithm -> if does_runtime_check then B.(modifies loc_none h0 h1) else False | _ -> False) /// It's a little difficult to deal with AES-GCM cleanly because we're missing a /// fallback C implementation. The two functions below guard the reference to the /// X64 AES-GCM code behind a test of `EverCrypt.TargetConfig.hacl_can_compile_vale`, /// which gets extracted to a preprocessor test, so that we can always compile them. /// In case the code is compiled on a system which doesn't support Vale, the functions /// are compiled in such a way that they make the program exit cleanly. [@@ Comment "WARNING: this function doesn't perform any dynamic hardware check. You MUST make sure your hardware supports the implementation of AESGCM. Besides, this function was not designed for cross-compilation: if you compile it on a system which doesn't support Vale, it will compile it to a function which makes the program exit."] val encrypt_expand_aes128_gcm_no_check: encrypt_expand_st false AES128_GCM [@@ Comment "WARNING: this function doesn't perform any dynamic hardware check. You MUST make sure your hardware supports the implementation of AESGCM. Besides, this function was not designed for cross-compilation: if you compile it on a system which doesn't support Vale, it will compile it to a function which makes the program exit."] val encrypt_expand_aes256_gcm_no_check: encrypt_expand_st false AES256_GCM /// Those functions take a key, expand it then perform encryption. They do not /// require calling create_in before. val encrypt_expand_aes128_gcm: encrypt_expand_st true AES128_GCM val encrypt_expand_aes256_gcm: encrypt_expand_st true AES256_GCM val encrypt_expand_chacha20_poly1305: encrypt_expand_st false CHACHA20_POLY1305 /// Run-time agility, run-time multiplexing, but not pre-expansion of the key. val encrypt_expand: #a:supported_alg -> encrypt_expand_st true (G.reveal a) /// Decryption (pre-allocated state) /// -------------------------------- inline_for_extraction noextract let decrypt_st (a: supported_alg) = s:B.pointer_or_null (state_s a) -> iv:iv_p a -> iv_len:UInt32.t { v iv_len = B.length iv /\ v iv_len > 0 } -> ad:ad_p a -> ad_len: UInt32.t { v ad_len = B.length ad /\ v ad_len <= pow2 31 } -> cipher: cipher_p a -> cipher_len: UInt32.t { v cipher_len = B.length cipher } -> tag: B.buffer uint8 { B.length tag = tag_length a } -> dst: B.buffer uint8 { B.length dst = B.length cipher } -> Stack error_code (requires fun h0 -> not (B.g_is_null s) ==> invariant h0 s /\ B.(loc_disjoint (footprint h0 s) (loc_buffer iv)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer ad)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer tag)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer dst)) /\ B.(loc_disjoint (footprint h0 s) (loc_buffer cipher)) /\ MB.(all_live h0 [ buf iv; buf ad; buf cipher; buf tag; buf dst ]) /\ B.disjoint tag dst /\ B.disjoint tag cipher /\ B.disjoint tag ad /\ B.disjoint cipher ad /\ B.disjoint dst ad /\ (B.disjoint cipher dst \/ cipher == dst)) (ensures fun h0 err h1 -> let cipher_tag = B.as_seq h0 cipher `S.append` B.as_seq h0 tag in match err with | InvalidKey -> B.g_is_null s /\ B.(modifies loc_none h0 h1) | Success -> not (B.g_is_null s) /\ ( let plain = Spec.decrypt #a (as_kv (B.deref h0 s)) (B.as_seq h0 iv) (B.as_seq h0 ad) cipher_tag in B.(modifies (loc_union (footprint h1 s) (loc_buffer dst)) h0 h1) /\ invariant h1 s /\ footprint h0 s == footprint h1 s /\ preserves_freeable s h0 h1 /\ as_kv (B.deref h1 s) == as_kv (B.deref h0 s) /\ Some? plain /\ S.equal (Some?.v plain) (B.as_seq h1 dst)) | AuthenticationFailure -> not (B.g_is_null s) /\ ( let plain = decrypt #a (as_kv (B.deref h0 s)) (B.as_seq h0 iv) (B.as_seq h0 ad) cipher_tag in B.(modifies (loc_union (footprint h1 s) (loc_buffer dst)) h0 h1) /\ invariant h1 s /\ footprint h0 s == footprint h1 s /\ preserves_freeable s h0 h1 /\ as_kv (B.deref h1 s) == as_kv (B.deref h0 s) /\ None? plain) | _ -> False) /// This function takes a previously expanded key and performs decryption. /// /// Possible return values are: /// - ``Success``: decryption was successfully performed /// - ``InvalidKey``: the function was passed a NULL expanded key (see above) /// - ``Failure``: cipher text could not be decrypted (e.g. tag mismatch) (** @type: true *) [@@ Comment "Verify the authenticity of `ad` || `cipher` and decrypt `cipher` into `dst`. @param s Pointer to the The AEAD state created by `EverCrypt_AEAD_create_in`. It already contains the encryption key. @param iv Pointer to `iv_len` bytes of memory where the nonce is read from. @param iv_len Length of the nonce. Note: ChaCha20Poly1305 requires a 12 byte nonce. @param ad Pointer to `ad_len` bytes of memory where the associated data is read from. @param ad_len Length of the associated data. @param cipher Pointer to `cipher_len` bytes of memory where the ciphertext is read from. @param cipher_len Length of the ciphertext. @param tag Pointer to `TAG_LEN` bytes of memory where the tag is read from. The length of the `tag` must be of a suitable length for the chosen algorithm: * `Spec_Agile_AEAD_AES128_GCM` (TAG_LEN=16) * `Spec_Agile_AEAD_AES256_GCM` (TAG_LEN=16) * `Spec_Agile_AEAD_CHACHA20_POLY1305` (TAG_LEN=16) @param dst Pointer to `cipher_len` bytes of memory where the decrypted plaintext will be written to. @return `EverCrypt_AEAD_decrypt` returns ... * `EverCrypt_Error_Success` ... on success and either of ... * `EverCrypt_Error_InvalidKey` (returned if and only if the `s` parameter is `NULL`), * `EverCrypt_Error_InvalidIVLength` (see note about requirements on IV size above), or * `EverCrypt_Error_AuthenticationFailure` (in case the ciphertext could not be authenticated, e.g., due to modifications) ... on failure (`EverCrypt_error.h`). Upon success, the plaintext will be written into `dst`."] val decrypt: #a:G.erased supported_alg -> decrypt_st (G.reveal a) /// Decryption (no pre-allocated state) /// -----------------------------------
{ "checked_file": "/", "dependencies": [ "Vale.X64.CPU_Features_s.fst.checked", "Spec.Agile.AEAD.fsti.checked", "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Integers.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "EverCrypt.TargetConfig.fsti.checked", "EverCrypt.Error.fsti.checked" ], "interface_file": false, "source_file": "EverCrypt.AEAD.fsti" }
[ { "abbrev": false, "full_module": "EverCrypt.Error", "short_module": null }, { "abbrev": true, "full_module": "Spec.Agile.AEAD", "short_module": "Spec" }, { "abbrev": false, "full_module": "Spec.Agile.AEAD", "short_module": null }, { "abbrev": false, "full_module": "FStar.Integers", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "MB" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "EverCrypt", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
does_runtime_check: Prims.bool -> a: Spec.Agile.AEAD.supported_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Spec.Agile.AEAD.supported_alg", "LowStar.Buffer.buffer", "Spec.Agile.AEAD.uint8", "Prims.b2t", "Prims.op_Equality", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.Integers.op_Greater_Equals", "FStar.Integers.Signed", "FStar.Integers.Winfinite", "LowStar.Monotonic.Buffer.length", "LowStar.Buffer.trivial_preorder", "Spec.Agile.AEAD.key_length", "EverCrypt.AEAD.iv_p", "FStar.UInt32.t", "Prims.l_and", "FStar.Integers.within_bounds", "FStar.Integers.Unsigned", "FStar.Integers.W32", "FStar.Integers.v", "FStar.Integers.op_Greater", "EverCrypt.AEAD.ad_p", "FStar.Integers.op_Less_Equals", "Prims.pow2", "EverCrypt.AEAD.cipher_p", "Spec.Agile.AEAD.tag_length", "Prims.nat", "EverCrypt.Error.error_code", "FStar.Monotonic.HyperStack.mem", "Prims.l_True", "EverCrypt.AEAD.config_pre", "Prims.logical", "LowStar.Monotonic.Buffer.all_live", "Prims.Cons", "LowStar.Monotonic.Buffer.buf_t", "LowStar.Monotonic.Buffer.buf", "Prims.Nil", "LowStar.Monotonic.Buffer.disjoint", "Prims.eq2", "FStar.Integers.op_Plus", "Spec.Agile.AEAD.max_length", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_buffer", "FStar.Pervasives.Native.uu___is_Some", "Spec.Agile.AEAD.decrypted", "FStar.Seq.Base.equal", "FStar.Pervasives.Native.__proj__Some__item__v", "LowStar.Monotonic.Buffer.as_seq", "FStar.Pervasives.Native.uu___is_None", "LowStar.Monotonic.Buffer.loc_none", "Prims.l_False", "FStar.Pervasives.Native.option", "Spec.Agile.AEAD.decrypt", "FStar.Seq.Base.seq", "FStar.Seq.Base.append" ]
[]
false
false
false
true
true
let decrypt_expand_st (does_runtime_check: bool) (a: supported_alg) =
k: B.buffer uint8 {B.length k = key_length a} -> iv: iv_p a -> iv_len: UInt32.t{v iv_len = B.length iv /\ v iv_len > 0} -> ad: ad_p a -> ad_len: UInt32.t{v ad_len = B.length ad /\ v ad_len <= pow2 31} -> cipher: cipher_p a -> cipher_len: UInt32.t{v cipher_len = B.length cipher} -> tag: B.buffer uint8 {B.length tag = tag_length a} -> dst: B.buffer uint8 {B.length dst = B.length cipher} -> Stack error_code (requires fun h0 -> (if does_runtime_check then True else config_pre a) /\ MB.(all_live h0 [buf k; buf iv; buf ad; buf cipher; buf tag; buf dst]) /\ B.disjoint k dst /\ B.disjoint tag dst /\ B.disjoint tag cipher /\ B.disjoint tag ad /\ B.disjoint cipher ad /\ B.disjoint dst ad /\ (B.disjoint cipher dst \/ cipher == dst)) (ensures fun h0 err h1 -> let cipher_tag = (B.as_seq h0 cipher) `S.append` (B.as_seq h0 tag) in let plain = Spec.decrypt #a (B.as_seq h0 k) (B.as_seq h0 iv) (B.as_seq h0 ad) cipher_tag in B.(modifies (loc_buffer dst) h0 h1) /\ (match err with | Success -> Some? plain /\ S.equal (Some?.v plain) (B.as_seq h1 dst) | AuthenticationFailure -> None? plain | UnsupportedAlgorithm -> if does_runtime_check then let open B in modifies loc_none h0 h1 else False | _ -> False))
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test1
val test1 (b1 b2 b3: ref) : SteelT int (((ptr b1) `star` (ptr b2)) `star` (ptr b3)) (fun _ -> ((ptr b1) `star` (ptr b2)) `star` (ptr b3))
val 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 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
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 52, "start_col": 0, "start_line": 47 }
(* 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
{ "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
b1: SteelFramingTestSuite.ref -> b2: SteelFramingTestSuite.ref -> b3: SteelFramingTestSuite.ref -> Steel.Effect.SteelT Prims.int
Steel.Effect.SteelT
[]
[]
[ "SteelFramingTestSuite.ref", "Prims.int", "SteelFramingTestSuite.read", "Steel.Effect.Common.star", "SteelFramingTestSuite.ptr", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
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
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.parse32_vldata_payload
val parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz {f i == true}) : Tot (parser32 (parse_vldata_payload sz f p i))
val parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz {f i == true}) : Tot (parser32 (parse_vldata_payload sz f p i))
let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 62, "end_line": 22, "start_col": 0, "start_line": 13 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
sz: LowParse.Spec.BoundedInt.integer_size -> f: (_: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) -> p32: LowParse.SLow.Base.parser32 p -> i: LowParse.Spec.BoundedInt.bounded_integer sz {f i == true} -> LowParse.SLow.Base.parser32 (LowParse.Spec.VLData.parse_vldata_payload sz f p i)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.BoundedInt.integer_size", "LowParse.Spec.BoundedInt.bounded_integer", "Prims.bool", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.SLow.Base.parser32", "Prims.eq2", "LowParse.SLow.Base.bytes32", "LowParse.SLow.FLData.parse32_fldata", "FStar.UInt32.v", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "FStar.UInt32.t", "LowParse.SLow.Base.parser32_correct", "LowParse.Spec.VLData.parse_vldata_payload_kind", "LowParse.Spec.VLData.parse_vldata_payload" ]
[]
false
false
false
false
false
let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz {f i == true}) : Tot (parser32 (parse_vldata_payload sz f p i)) =
fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.parse32_vldata
val parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p))
val parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p))
let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 78, "end_line": 50, "start_col": 0, "start_line": 43 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
sz: LowParse.Spec.BoundedInt.integer_size -> p32: LowParse.SLow.Base.parser32 p -> LowParse.SLow.Base.parser32 (LowParse.Spec.VLData.parse_vldata sz p)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.BoundedInt.integer_size", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.SLow.Base.parser32", "LowParse.SLow.VLData.parse32_vldata_gen", "LowParse.Spec.VLData.unconstrained_bounded_integer", "LowParse.Spec.BoundedInt.bounded_integer", "Prims.bool", "Prims.eq2", "LowParse.Spec.VLData.parse_vldata_gen_kind", "LowParse.Spec.VLData.parse_vldata" ]
[]
false
false
false
false
false
let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) =
parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.parse32_vldata_gen
val parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f': (x: bounded_integer sz -> Tot (y: bool{y == f x}))) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p))
val parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f': (x: bounded_integer sz -> Tot (y: bool{y == f x}))) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p))
let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32)
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 37, "end_line": 40, "start_col": 0, "start_line": 25 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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
sz: LowParse.Spec.BoundedInt.integer_size -> f: (_: LowParse.Spec.BoundedInt.bounded_integer sz -> Prims.GTot Prims.bool) -> f': (x: LowParse.Spec.BoundedInt.bounded_integer sz -> y: Prims.bool{y == f x}) -> p32: LowParse.SLow.Base.parser32 p -> LowParse.SLow.Base.parser32 (LowParse.Spec.VLData.parse_vldata_gen sz f p)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.BoundedInt.integer_size", "LowParse.Spec.BoundedInt.bounded_integer", "Prims.bool", "Prims.eq2", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.SLow.Base.parser32", "LowParse.SLow.Combinators.parse32_and_then", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.Combinators.parse_filter", "LowParse.Spec.BoundedInt.parse_bounded_integer", "LowParse.SLow.Combinators.parse32_filter", "LowParse.SLow.BoundedInt.parse32_bounded_integer", "LowParse.Spec.VLData.parse_vldata_payload_kind", "LowParse.Spec.VLData.parse_vldata_payload", "LowParse.SLow.VLData.parse32_vldata_payload", "Prims.unit", "LowParse.Spec.VLData.parse_vldata_gen_eq_def", "LowParse.Spec.VLData.parse_vldata_gen_kind", "LowParse.Spec.VLData.parse_vldata_gen" ]
[]
false
false
false
false
false
let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f': (x: bounded_integer sz -> Tot (y: bool{y == f x}))) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) =
[@@ inline_let ]let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32)
false
CustomSyntax.fst
CustomSyntax.folded_pts_to
val folded_pts_to (r: ref U32.t) (n: erased U32.t) : vprop
val folded_pts_to (r: ref U32.t) (n: erased U32.t) : vprop
let folded_pts_to (r:ref U32.t) (n:erased U32.t) : vprop = pts_to r n
{ "file_name": "share/steel/examples/pulse/CustomSyntax.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 69, "end_line": 26, "start_col": 0, "start_line": 26 }
(* 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)
{ "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
r: Pulse.Lib.Reference.ref FStar.UInt32.t -> n: FStar.Ghost.erased FStar.UInt32.t -> Pulse.Lib.Core.vprop
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.Reference.ref", "FStar.UInt32.t", "FStar.Ghost.erased", "Pulse.Lib.Reference.pts_to", "PulseCore.FractionalPermission.full_perm", "FStar.Ghost.reveal", "Pulse.Lib.Core.vprop" ]
[]
false
false
false
true
false
let folded_pts_to (r: ref U32.t) (n: erased U32.t) : vprop =
pts_to r n
false
Spec.Agile.DH.fst
Spec.Agile.DH.prime
val prime : a: Spec.Agile.DH.algorithm -> Prims.pos
let prime (a:algorithm) = match a with | DH_Curve25519 -> Spec.Curve25519.prime | DH_P256 -> Spec.P256.prime
{ "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": 30, "end_line": 31, "start_col": 0, "start_line": 28 }
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
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.DH.algorithm -> Prims.pos
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.DH.algorithm", "Spec.Curve25519.prime", "Spec.P256.PointOps.prime", "Prims.pos" ]
[]
false
false
false
true
false
let prime (a: algorithm) =
match a with | DH_Curve25519 -> Spec.Curve25519.prime | DH_P256 -> Spec.P256.prime
false
Spec.Agile.DH.fst
Spec.Agile.DH.size_key
val size_key (a: algorithm) : Tot size_nat
val size_key (a: algorithm) : Tot size_nat
let size_key (a:algorithm) : Tot size_nat = match a with | DH_Curve25519 -> 32 | DH_P256 -> 32
{ "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": 17, "end_line": 19, "start_col": 0, "start_line": 16 }
module Spec.Agile.DH open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence /// Constants type algorithm = | DH_Curve25519 | DH_P256
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.DH.algorithm -> Lib.IntTypes.size_nat
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.DH.algorithm", "Lib.IntTypes.size_nat" ]
[]
false
false
false
true
false
let size_key (a: algorithm) : Tot size_nat =
match a with | DH_Curve25519 -> 32 | DH_P256 -> 32
false
Spec.Agile.DH.fst
Spec.Agile.DH.size_public
val size_public (a: algorithm) : Tot size_nat
val size_public (a: algorithm) : Tot size_nat
let size_public (a:algorithm) : Tot size_nat = match a with | DH_Curve25519 -> 32 | DH_P256 -> 64
{ "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": 17, "end_line": 25, "start_col": 0, "start_line": 22 }
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
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.DH.algorithm -> Lib.IntTypes.size_nat
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.DH.algorithm", "Lib.IntTypes.size_nat" ]
[]
false
false
false
true
false
let size_public (a: algorithm) : Tot size_nat =
match a with | DH_Curve25519 -> 32 | DH_P256 -> 64
false
Spec.Agile.DH.fst
Spec.Agile.DH.secret_to_public
val secret_to_public: a:algorithm -> scalar a -> Tot (option (serialized_point a))
val secret_to_public: a:algorithm -> scalar a -> Tot (option (serialized_point a))
let secret_to_public a kpriv = match a with | DH_Curve25519 -> Some (Spec.Curve25519.secret_to_public kpriv) | DH_P256 -> Spec.P256.secret_to_public kpriv
{ "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": 47, "end_line": 62, "start_col": 0, "start_line": 59 }
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" 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
{ "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 -> kpriv: Spec.Agile.DH.scalar a -> FStar.Pervasives.Native.option (Spec.Agile.DH.serialized_point a)
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.DH.algorithm", "Spec.Agile.DH.scalar", "FStar.Pervasives.Native.Some", "Spec.Agile.DH.serialized_point", "Spec.Curve25519.secret_to_public", "Spec.P256.secret_to_public", "FStar.Pervasives.Native.option" ]
[]
false
false
false
false
false
let secret_to_public a kpriv =
match a with | DH_Curve25519 -> Some (Spec.Curve25519.secret_to_public kpriv) | DH_P256 -> Spec.P256.secret_to_public kpriv
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.parse32_bounded_vldata'
val parse32_bounded_vldata' (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p))
val parse32_bounded_vldata' (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p))
let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input)
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 118, "end_line": 70, "start_col": 0, "start_line": 55 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> min32: FStar.UInt32.t{FStar.UInt32.v min32 == min} -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> max32: FStar.UInt32.t{FStar.UInt32.v max32 == max} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> p32: LowParse.SLow.Base.parser32 p -> LowParse.SLow.Base.parser32 (LowParse.Spec.VLData.parse_bounded_vldata' min max l p)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.BoundedInt.log256'", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.SLow.Base.parser32", "LowParse.SLow.Base.bytes32", "LowParse.SLow.VLData.parse32_vldata_gen", "LowParse.Spec.BoundedInt.in_bounds", "LowParse.Spec.BoundedInt.bounded_integer", "Prims.op_Negation", "Prims.op_BarBar", "FStar.UInt32.lt", "Prims.bool", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.SLow.Base.parser32_correct", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.VLData.parse_bounded_vldata'", "LowParse.Spec.BoundedInt.integer_size", "Prims.unit", "LowParse.Spec.VLData.parse_bounded_vldata_correct" ]
[]
false
false
false
false
false
let parse32_bounded_vldata' (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) =
[@@ inline_let ]let _ = parse_bounded_vldata_correct min max l p in [@@ inline_let ]let sz:integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input)
false
Spec.Agile.DH.fst
Spec.Agile.DH.clamp
val clamp: alg:algorithm{alg = DH_Curve25519} -> scalar alg -> Tot (scalar alg)
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
{ "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": 54, "end_line": 44, "start_col": 0, "start_line": 42 }
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
{ "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": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
alg: Spec.Agile.DH.algorithm{alg = Spec.Agile.DH.DH_Curve25519} -> k: Spec.Agile.DH.scalar alg -> Spec.Agile.DH.scalar alg
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.DH.algorithm", "Prims.b2t", "Prims.op_Equality", "Spec.Agile.DH.DH_Curve25519", "Spec.Agile.DH.scalar", "Spec.Curve25519.decodeScalar" ]
[]
false
false
false
false
false
let clamp a k =
match a with | DH.DH_Curve25519 -> Spec.Curve25519.decodeScalar k
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.parse32_bounded_vldata_strong_aux
val parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t))
val parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t))
let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1 : t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed)
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 77, "end_line": 113, "start_col": 0, "start_line": 86 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input) inline_for_extraction let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> min32: FStar.UInt32.t{FStar.UInt32.v min32 == min} -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> max32: FStar.UInt32.t{FStar.UInt32.v max32 == max} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> s: LowParse.Spec.Base.serializer p -> p32: LowParse.SLow.Base.parser32 p -> input: LowParse.SLow.Base.bytes32 -> FStar.Pervasives.Native.option (LowParse.Spec.VLData.parse_bounded_vldata_strong_t min max s * FStar.UInt32.t)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.BoundedInt.log256'", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.parser32", "LowParse.SLow.Base.bytes32", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.Spec.VLData.parse_bounded_vldata_strong_pred", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "LowParse.SLow.Base.parser32_correct", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Combinators.parse_strengthen", "LowParse.Spec.VLData.parse_bounded_vldata'", "LowParse.Spec.VLData.parse_bounded_vldata_strong_correct", "LowParse.SLow.Combinators.parse32_strengthen", "LowParse.SLow.VLData.parse32_bounded_vldata'" ]
[]
false
false
false
false
false
let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) =
let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1:t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed)
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.parse32_bounded_vldata
val parse32_bounded_vldata (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p))
val parse32_bounded_vldata (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p))
let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 63, "end_line": 83, "start_col": 0, "start_line": 73 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> min32: FStar.UInt32.t{FStar.UInt32.v min32 == min} -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> max32: FStar.UInt32.t{FStar.UInt32.v max32 == max} -> p32: LowParse.SLow.Base.parser32 p -> LowParse.SLow.Base.parser32 (LowParse.Spec.VLData.parse_bounded_vldata min max p)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.SLow.Base.parser32", "LowParse.SLow.VLData.parse32_bounded_vldata'", "LowParse.Spec.BoundedInt.log256'", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.VLData.parse_bounded_vldata" ]
[]
false
false
false
false
false
let parse32_bounded_vldata (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) =
parse32_bounded_vldata' min min32 max max32 (log256' max) p32
false
CustomSyntax.fst
CustomSyntax.mpts_to
val mpts_to (r: ref U32.t) (n: erased U32.t) : vprop
val mpts_to (r: ref U32.t) (n: erased U32.t) : vprop
let mpts_to (r:ref U32.t) (n:erased U32.t) : vprop = pts_to r n
{ "file_name": "share/steel/examples/pulse/CustomSyntax.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 63, "end_line": 240, "start_col": 0, "start_line": 240 }
(* 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 }; () } ```
{ "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
r: Pulse.Lib.Reference.ref FStar.UInt32.t -> n: FStar.Ghost.erased FStar.UInt32.t -> Pulse.Lib.Core.vprop
Prims.Tot
[ "total" ]
[]
[ "Pulse.Lib.Reference.ref", "FStar.UInt32.t", "FStar.Ghost.erased", "Pulse.Lib.Reference.pts_to", "PulseCore.FractionalPermission.full_perm", "FStar.Ghost.reveal", "Pulse.Lib.Core.vprop" ]
[]
false
false
false
true
false
let mpts_to (r: ref U32.t) (n: erased U32.t) : vprop =
pts_to r n
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.parse32_bounded_vldata_strong'
val parse32_bounded_vldata_strong' (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s))
val parse32_bounded_vldata_strong' (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s))
let parse32_bounded_vldata_strong' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s)) = make_parser32 (parse_bounded_vldata_strong' min max l s) (fun input -> parse32_bounded_vldata_strong_correct min min32 max max32 l s p32 input; parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input )
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 167, "start_col": 0, "start_line": 150 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input) inline_for_extraction let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32 inline_for_extraction let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1 : t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) let parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma ( let res : option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> () | Some (x, consumed) -> let x1 : t = x in let res = Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) in assert (parser32_correct (parse_bounded_vldata_strong' min max l s) input res)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> min32: FStar.UInt32.t{FStar.UInt32.v min32 == min} -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> max32: FStar.UInt32.t{FStar.UInt32.v max32 == max} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> s: LowParse.Spec.Base.serializer p -> p32: LowParse.SLow.Base.parser32 p -> LowParse.SLow.Base.parser32 (LowParse.Spec.VLData.parse_bounded_vldata_strong' min max l s)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.BoundedInt.log256'", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.parser32", "LowParse.SLow.Base.make_parser32", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.Spec.VLData.parse_bounded_vldata_strong'", "LowParse.SLow.Base.bytes32", "LowParse.SLow.VLData.parse32_bounded_vldata_strong_aux", "Prims.unit", "LowParse.SLow.VLData.parse32_bounded_vldata_strong_correct", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
false
false
let parse32_bounded_vldata_strong' (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s)) =
make_parser32 (parse_bounded_vldata_strong' min max l s) (fun input -> parse32_bounded_vldata_strong_correct min min32 max max32 l s p32 input; parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input)
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.size32_bounded_vldata_strong
val size32_bounded_vldata_strong (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (sz32: U32.t{U32.v sz32 == log256' max}) : Tot (size32 (serialize_bounded_vldata_strong min max s))
val size32_bounded_vldata_strong (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (sz32: U32.t{U32.v sz32 == log256' max}) : Tot (size32 (serialize_bounded_vldata_strong min max s))
let size32_bounded_vldata_strong (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4, otherwise add overflows (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (sz32: U32.t { U32.v sz32 == log256' max } ) : Tot (size32 (serialize_bounded_vldata_strong min max s)) = size32_bounded_vldata_strong' min max (log256' max) s32 sz32
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 62, "end_line": 354, "start_col": 0, "start_line": 344 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input) inline_for_extraction let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32 inline_for_extraction let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1 : t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) let parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma ( let res : option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> () | Some (x, consumed) -> let x1 : t = x in let res = Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) in assert (parser32_correct (parse_bounded_vldata_strong' min max l s) input res) inline_for_extraction let parse32_bounded_vldata_strong' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s)) = make_parser32 (parse_bounded_vldata_strong' min max l s) (fun input -> parse32_bounded_vldata_strong_correct min min32 max max32 l s p32 input; parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input ) inline_for_extraction let parse32_bounded_vldata_strong (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong min max s)) = parse32_bounded_vldata_strong' min min32 max max32 (log256' max) s p32 inline_for_extraction let serialize32_bounded_vldata_strong_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (parse_bounded_vldata_strong_t min max s -> Tot bytes32) = [@inline_let] let sz : integer_size = l in [@inline_let] let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in (fun (input: parse_bounded_vldata_strong_t min max s) -> let pl = s32 input in let len = B32.len pl in assert (min <= U32.v len /\ U32.v len <= max); let slen = ser (len <: bounded_integer sz) in seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in res) let serialize32_bounded_vldata_strong_correct (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) (input: parse_bounded_vldata_strong_t min max s) : Lemma (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input (serialize32_bounded_vldata_strong_aux min max l s32 input)) = let sz : integer_size = l in let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in let pl = s32 input in assert (B32.reveal pl == s input); let len = B32.len pl in let nlen = U32.v len in assert (min <= nlen /\ nlen <= max); let slen = ser (len <: bounded_integer sz) in assert (B32.reveal slen == serialize (serialize_bounded_integer sz) len); seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in assert (B32.reveal res == Seq.append (B32.reveal slen) (B32.reveal pl)); assert (B32.reveal res == serialize_bounded_vldata_strong_aux min max l s input); assert (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res) inline_for_extraction let serialize32_bounded_vldata_strong' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong' min max l s)) = fun (input: parse_bounded_vldata_strong_t min max s) -> serialize32_bounded_vldata_strong_correct min max l s32 input; (serialize32_bounded_vldata_strong_aux min max l s32 input <: (res: bytes32 { serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res } )) inline_for_extraction let serialize32_bounded_vldata_strong (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong min max s)) = serialize32_bounded_vldata_strong' min max (log256' max) s32 inline_for_extraction let serialize32_bounded_vldata (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { serialize_bounded_vldata_precond min max k } ) : Tot (serializer32 (serialize_bounded_vldata min max s)) = fun (input: t) -> [@inline_let] let _ : unit = let Some (_, consumed) = parse p (serialize s input) in () in serialize32_bounded_vldata_strong_correct min max (log256' max) s32 input; (serialize32_bounded_vldata_strong_aux min max (log256' max) s32 input <: (res: bytes32 { serializer32_correct (serialize_bounded_vldata min max s) input res } )) #reset-options "--z3rlimit 32 --z3cliopt smt.arith.nl=false" inline_for_extraction let check_vldata_payload_size32 (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967295 } ) // necessary to exclude the overflow case; enough to be compatible with serialize32 (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (input: t) : Tot (y: bool { y == true <==> parse_bounded_vldata_strong_pred min max s input } ) = let sz : U32.t = s32 input in [@inline_let] let y : bool = not (sz = u32_max || U32.lt sz min32 || U32.lt max32 sz) in [@inline_let] let _ : squash (y == true <==> parse_bounded_vldata_strong_pred min max s input) = if sz = u32_max then if Seq.length (serialize s input) > U32.v u32_max then () else begin assert (U32.v u32_max == Seq.length (serialize s input)); assert_norm (U32.v u32_max == 4294967295); assert (Seq.length (serialize s input) > max); assert (~ (parse_bounded_vldata_strong_pred min max s input)) end else if Seq.length (serialize s input) > U32.v u32_max then () else () in y inline_for_extraction let size32_bounded_vldata_strong' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4, otherwise add overflows (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (sz32: U32.t { U32.v sz32 == l } ) : Tot (size32 (serialize_bounded_vldata_strong' min max l s)) = (fun (input: parse_bounded_vldata_strong_t min max s) -> let len = s32 input in [@inline_let] let _ = assert_norm (U32.v u32_max == 4294967295) in [@inline_let] let _ = assert (min <= U32.v len /\ U32.v len <= max) in [@inline_let] let res : U32.t = U32.add sz32 len in (res <: (res: U32.t { size32_postcond (serialize_bounded_vldata_strong' min max l s) input res } )))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967292} -> s32: LowParse.SLow.Base.size32 s -> sz32: FStar.UInt32.t{FStar.UInt32.v sz32 == LowParse.Spec.BoundedInt.log256' max} -> LowParse.SLow.Base.size32 (LowParse.Spec.VLData.serialize_bounded_vldata_strong min max s)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.size32", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "LowParse.Spec.BoundedInt.log256'", "LowParse.SLow.VLData.size32_bounded_vldata_strong'", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.Spec.VLData.parse_bounded_vldata_strong", "LowParse.Spec.VLData.serialize_bounded_vldata_strong" ]
[]
false
false
false
false
false
let size32_bounded_vldata_strong (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (sz32: U32.t{U32.v sz32 == log256' max}) : Tot (size32 (serialize_bounded_vldata_strong min max s)) =
size32_bounded_vldata_strong' min max (log256' max) s32 sz32
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.parse32_bounded_vldata_strong
val parse32_bounded_vldata_strong (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong min max s))
val parse32_bounded_vldata_strong (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong min max s))
let parse32_bounded_vldata_strong (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong min max s)) = parse32_bounded_vldata_strong' min min32 max max32 (log256' max) s p32
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 72, "end_line": 181, "start_col": 0, "start_line": 170 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input) inline_for_extraction let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32 inline_for_extraction let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1 : t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) let parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma ( let res : option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> () | Some (x, consumed) -> let x1 : t = x in let res = Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) in assert (parser32_correct (parse_bounded_vldata_strong' min max l s) input res) inline_for_extraction let parse32_bounded_vldata_strong' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s)) = make_parser32 (parse_bounded_vldata_strong' min max l s) (fun input -> parse32_bounded_vldata_strong_correct min min32 max max32 l s p32 input; parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> min32: FStar.UInt32.t{FStar.UInt32.v min32 == min} -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> max32: FStar.UInt32.t{FStar.UInt32.v max32 == max} -> s: LowParse.Spec.Base.serializer p -> p32: LowParse.SLow.Base.parser32 p -> LowParse.SLow.Base.parser32 (LowParse.Spec.VLData.parse_bounded_vldata_strong min max s)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.parser32", "LowParse.SLow.VLData.parse32_bounded_vldata_strong'", "LowParse.Spec.BoundedInt.log256'", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.Spec.VLData.parse_bounded_vldata_strong" ]
[]
false
false
false
false
false
let parse32_bounded_vldata_strong (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong min max s)) =
parse32_bounded_vldata_strong' min min32 max max32 (log256' max) s p32
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.parse32_bounded_vldata_strong_correct
val parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma (let res:option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res)
val parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma (let res:option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res)
let parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma ( let res : option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> () | Some (x, consumed) -> let x1 : t = x in let res = Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) in assert (parser32_correct (parse_bounded_vldata_strong' min max l s) input res)
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 82, "end_line": 147, "start_col": 0, "start_line": 115 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input) inline_for_extraction let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32 inline_for_extraction let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1 : t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> min32: FStar.UInt32.t{FStar.UInt32.v min32 == min} -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> max32: FStar.UInt32.t{FStar.UInt32.v max32 == max} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> s: LowParse.Spec.Base.serializer p -> p32: LowParse.SLow.Base.parser32 p -> input: LowParse.SLow.Base.bytes32 -> FStar.Pervasives.Lemma (ensures (let res = LowParse.SLow.VLData.parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in LowParse.SLow.Base.parser32_correct (LowParse.Spec.VLData.parse_bounded_vldata_strong' min max l s) input res))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.BoundedInt.log256'", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.parser32", "LowParse.SLow.Base.bytes32", "LowParse.Spec.VLData.parse_bounded_vldata_strong_pred", "Prims._assert", "LowParse.SLow.Base.parser32_correct", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.Spec.VLData.parse_bounded_vldata_strong'", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "LowParse.Spec.Combinators.parse_strengthen", "LowParse.Spec.VLData.parse_bounded_vldata'", "LowParse.Spec.VLData.parse_bounded_vldata_strong_correct", "LowParse.SLow.Combinators.parse32_strengthen", "LowParse.SLow.VLData.parse32_bounded_vldata'", "Prims.l_True", "Prims.squash", "LowParse.SLow.VLData.parse32_bounded_vldata_strong_aux", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (max32: U32.t{U32.v max32 == max}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma (let res:option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res) =
let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> () | Some (x, consumed) -> let x1:t = x in let res = Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) in assert (parser32_correct (parse_bounded_vldata_strong' min max l s) input res)
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.serialize32_bounded_vldata_strong
val serialize32_bounded_vldata_strong (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong min max s))
val serialize32_bounded_vldata_strong (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong min max s))
let serialize32_bounded_vldata_strong (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong min max s)) = serialize32_bounded_vldata_strong' min max (log256' max) s32
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 62, "end_line": 261, "start_col": 0, "start_line": 252 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input) inline_for_extraction let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32 inline_for_extraction let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1 : t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) let parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma ( let res : option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> () | Some (x, consumed) -> let x1 : t = x in let res = Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) in assert (parser32_correct (parse_bounded_vldata_strong' min max l s) input res) inline_for_extraction let parse32_bounded_vldata_strong' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s)) = make_parser32 (parse_bounded_vldata_strong' min max l s) (fun input -> parse32_bounded_vldata_strong_correct min min32 max max32 l s p32 input; parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input ) inline_for_extraction let parse32_bounded_vldata_strong (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong min max s)) = parse32_bounded_vldata_strong' min min32 max max32 (log256' max) s p32 inline_for_extraction let serialize32_bounded_vldata_strong_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (parse_bounded_vldata_strong_t min max s -> Tot bytes32) = [@inline_let] let sz : integer_size = l in [@inline_let] let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in (fun (input: parse_bounded_vldata_strong_t min max s) -> let pl = s32 input in let len = B32.len pl in assert (min <= U32.v len /\ U32.v len <= max); let slen = ser (len <: bounded_integer sz) in seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in res) let serialize32_bounded_vldata_strong_correct (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) (input: parse_bounded_vldata_strong_t min max s) : Lemma (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input (serialize32_bounded_vldata_strong_aux min max l s32 input)) = let sz : integer_size = l in let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in let pl = s32 input in assert (B32.reveal pl == s input); let len = B32.len pl in let nlen = U32.v len in assert (min <= nlen /\ nlen <= max); let slen = ser (len <: bounded_integer sz) in assert (B32.reveal slen == serialize (serialize_bounded_integer sz) len); seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in assert (B32.reveal res == Seq.append (B32.reveal slen) (B32.reveal pl)); assert (B32.reveal res == serialize_bounded_vldata_strong_aux min max l s input); assert (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res) inline_for_extraction let serialize32_bounded_vldata_strong' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong' min max l s)) = fun (input: parse_bounded_vldata_strong_t min max s) -> serialize32_bounded_vldata_strong_correct min max l s32 input; (serialize32_bounded_vldata_strong_aux min max l s32 input <: (res: bytes32 { serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res } ))
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967292} -> s32: LowParse.SLow.Base.partial_serializer32 s -> LowParse.SLow.Base.serializer32 (LowParse.Spec.VLData.serialize_bounded_vldata_strong min max s )
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.partial_serializer32", "LowParse.SLow.VLData.serialize32_bounded_vldata_strong'", "LowParse.Spec.BoundedInt.log256'", "LowParse.SLow.Base.serializer32", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.Spec.VLData.parse_bounded_vldata_strong", "LowParse.Spec.VLData.serialize_bounded_vldata_strong" ]
[]
false
false
false
false
false
let serialize32_bounded_vldata_strong (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong min max s)) =
serialize32_bounded_vldata_strong' min max (log256' max) s32
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.serialize32_bounded_vldata_strong'
val serialize32_bounded_vldata_strong' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong' min max l s))
val serialize32_bounded_vldata_strong' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong' min max l s))
let serialize32_bounded_vldata_strong' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong' min max l s)) = fun (input: parse_bounded_vldata_strong_t min max s) -> serialize32_bounded_vldata_strong_correct min max l s32 input; (serialize32_bounded_vldata_strong_aux min max l s32 input <: (res: bytes32 { serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res } ))
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 162, "end_line": 249, "start_col": 0, "start_line": 237 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input) inline_for_extraction let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32 inline_for_extraction let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1 : t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) let parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma ( let res : option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> () | Some (x, consumed) -> let x1 : t = x in let res = Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) in assert (parser32_correct (parse_bounded_vldata_strong' min max l s) input res) inline_for_extraction let parse32_bounded_vldata_strong' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s)) = make_parser32 (parse_bounded_vldata_strong' min max l s) (fun input -> parse32_bounded_vldata_strong_correct min min32 max max32 l s p32 input; parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input ) inline_for_extraction let parse32_bounded_vldata_strong (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong min max s)) = parse32_bounded_vldata_strong' min min32 max max32 (log256' max) s p32 inline_for_extraction let serialize32_bounded_vldata_strong_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (parse_bounded_vldata_strong_t min max s -> Tot bytes32) = [@inline_let] let sz : integer_size = l in [@inline_let] let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in (fun (input: parse_bounded_vldata_strong_t min max s) -> let pl = s32 input in let len = B32.len pl in assert (min <= U32.v len /\ U32.v len <= max); let slen = ser (len <: bounded_integer sz) in seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in res) let serialize32_bounded_vldata_strong_correct (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) (input: parse_bounded_vldata_strong_t min max s) : Lemma (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input (serialize32_bounded_vldata_strong_aux min max l s32 input)) = let sz : integer_size = l in let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in let pl = s32 input in assert (B32.reveal pl == s input); let len = B32.len pl in let nlen = U32.v len in assert (min <= nlen /\ nlen <= max); let slen = ser (len <: bounded_integer sz) in assert (B32.reveal slen == serialize (serialize_bounded_integer sz) len); seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in assert (B32.reveal res == Seq.append (B32.reveal slen) (B32.reveal pl)); assert (B32.reveal res == serialize_bounded_vldata_strong_aux min max l s input); assert (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967292} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> s32: LowParse.SLow.Base.partial_serializer32 s -> LowParse.SLow.Base.serializer32 (LowParse.Spec.VLData.serialize_bounded_vldata_strong' min max l s)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.partial_serializer32", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.SLow.VLData.serialize32_bounded_vldata_strong_aux", "LowParse.SLow.Base.bytes32", "LowParse.SLow.Base.serializer32_correct", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong'", "LowParse.Spec.VLData.serialize_bounded_vldata_strong'", "Prims.unit", "LowParse.SLow.VLData.serialize32_bounded_vldata_strong_correct", "LowParse.SLow.Base.serializer32" ]
[]
false
false
false
false
false
let serialize32_bounded_vldata_strong' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong' min max l s)) =
fun (input: parse_bounded_vldata_strong_t min max s) -> serialize32_bounded_vldata_strong_correct min max l s32 input; (serialize32_bounded_vldata_strong_aux min max l s32 input <: (res: bytes32{serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res}))
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.serialize32_bounded_vldata
val serialize32_bounded_vldata (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s {serialize_bounded_vldata_precond min max k}) : Tot (serializer32 (serialize_bounded_vldata min max s))
val serialize32_bounded_vldata (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s {serialize_bounded_vldata_precond min max k}) : Tot (serializer32 (serialize_bounded_vldata min max s))
let serialize32_bounded_vldata (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { serialize_bounded_vldata_precond min max k } ) : Tot (serializer32 (serialize_bounded_vldata min max s)) = fun (input: t) -> [@inline_let] let _ : unit = let Some (_, consumed) = parse p (serialize s input) in () in serialize32_bounded_vldata_strong_correct min max (log256' max) s32 input; (serialize32_bounded_vldata_strong_aux min max (log256' max) s32 input <: (res: bytes32 { serializer32_correct (serialize_bounded_vldata min max s) input res } ))
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 164, "end_line": 280, "start_col": 0, "start_line": 264 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input) inline_for_extraction let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32 inline_for_extraction let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1 : t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) let parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma ( let res : option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> () | Some (x, consumed) -> let x1 : t = x in let res = Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) in assert (parser32_correct (parse_bounded_vldata_strong' min max l s) input res) inline_for_extraction let parse32_bounded_vldata_strong' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s)) = make_parser32 (parse_bounded_vldata_strong' min max l s) (fun input -> parse32_bounded_vldata_strong_correct min min32 max max32 l s p32 input; parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input ) inline_for_extraction let parse32_bounded_vldata_strong (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong min max s)) = parse32_bounded_vldata_strong' min min32 max max32 (log256' max) s p32 inline_for_extraction let serialize32_bounded_vldata_strong_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (parse_bounded_vldata_strong_t min max s -> Tot bytes32) = [@inline_let] let sz : integer_size = l in [@inline_let] let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in (fun (input: parse_bounded_vldata_strong_t min max s) -> let pl = s32 input in let len = B32.len pl in assert (min <= U32.v len /\ U32.v len <= max); let slen = ser (len <: bounded_integer sz) in seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in res) let serialize32_bounded_vldata_strong_correct (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) (input: parse_bounded_vldata_strong_t min max s) : Lemma (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input (serialize32_bounded_vldata_strong_aux min max l s32 input)) = let sz : integer_size = l in let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in let pl = s32 input in assert (B32.reveal pl == s input); let len = B32.len pl in let nlen = U32.v len in assert (min <= nlen /\ nlen <= max); let slen = ser (len <: bounded_integer sz) in assert (B32.reveal slen == serialize (serialize_bounded_integer sz) len); seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in assert (B32.reveal res == Seq.append (B32.reveal slen) (B32.reveal pl)); assert (B32.reveal res == serialize_bounded_vldata_strong_aux min max l s input); assert (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res) inline_for_extraction let serialize32_bounded_vldata_strong' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong' min max l s)) = fun (input: parse_bounded_vldata_strong_t min max s) -> serialize32_bounded_vldata_strong_correct min max l s32 input; (serialize32_bounded_vldata_strong_aux min max l s32 input <: (res: bytes32 { serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res } )) inline_for_extraction let serialize32_bounded_vldata_strong (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong min max s)) = serialize32_bounded_vldata_strong' min max (log256' max) s32
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967292} -> s32: LowParse.SLow.Base.partial_serializer32 s {LowParse.Spec.VLData.serialize_bounded_vldata_precond min max k} -> LowParse.SLow.Base.serializer32 (LowParse.Spec.VLData.serialize_bounded_vldata min max s)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.partial_serializer32", "LowParse.Spec.VLData.serialize_bounded_vldata_precond", "LowParse.SLow.VLData.serialize32_bounded_vldata_strong_aux", "LowParse.Spec.BoundedInt.log256'", "LowParse.SLow.Base.bytes32", "LowParse.SLow.Base.serializer32_correct", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.VLData.parse_bounded_vldata", "LowParse.Spec.VLData.serialize_bounded_vldata", "Prims.unit", "LowParse.SLow.VLData.serialize32_bounded_vldata_strong_correct", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.serialize", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.parse", "LowParse.SLow.Base.serializer32" ]
[]
false
false
false
false
false
let serialize32_bounded_vldata (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s {serialize_bounded_vldata_precond min max k}) : Tot (serializer32 (serialize_bounded_vldata min max s)) =
fun (input: t) -> [@@ inline_let ]let _:unit = let Some (_, consumed) = parse p (serialize s input) in () in serialize32_bounded_vldata_strong_correct min max (log256' max) s32 input; (serialize32_bounded_vldata_strong_aux min max (log256' max) s32 input <: (res: bytes32{serializer32_correct (serialize_bounded_vldata min max s) input res}))
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.serialize32_bounded_vldata_strong_correct
val serialize32_bounded_vldata_strong_correct (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) (input: parse_bounded_vldata_strong_t min max s) : Lemma (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input (serialize32_bounded_vldata_strong_aux min max l s32 input))
val serialize32_bounded_vldata_strong_correct (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) (input: parse_bounded_vldata_strong_t min max s) : Lemma (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input (serialize32_bounded_vldata_strong_aux min max l s32 input))
let serialize32_bounded_vldata_strong_correct (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) (input: parse_bounded_vldata_strong_t min max s) : Lemma (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input (serialize32_bounded_vldata_strong_aux min max l s32 input)) = let sz : integer_size = l in let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in let pl = s32 input in assert (B32.reveal pl == s input); let len = B32.len pl in let nlen = U32.v len in assert (min <= nlen /\ nlen <= max); let slen = ser (len <: bounded_integer sz) in assert (B32.reveal slen == serialize (serialize_bounded_integer sz) len); seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in assert (B32.reveal res == Seq.append (B32.reveal slen) (B32.reveal pl)); assert (B32.reveal res == serialize_bounded_vldata_strong_aux min max l s input); assert (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res)
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 88, "end_line": 234, "start_col": 0, "start_line": 208 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input) inline_for_extraction let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32 inline_for_extraction let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1 : t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) let parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma ( let res : option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> () | Some (x, consumed) -> let x1 : t = x in let res = Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) in assert (parser32_correct (parse_bounded_vldata_strong' min max l s) input res) inline_for_extraction let parse32_bounded_vldata_strong' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s)) = make_parser32 (parse_bounded_vldata_strong' min max l s) (fun input -> parse32_bounded_vldata_strong_correct min min32 max max32 l s p32 input; parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input ) inline_for_extraction let parse32_bounded_vldata_strong (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong min max s)) = parse32_bounded_vldata_strong' min min32 max max32 (log256' max) s p32 inline_for_extraction let serialize32_bounded_vldata_strong_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (parse_bounded_vldata_strong_t min max s -> Tot bytes32) = [@inline_let] let sz : integer_size = l in [@inline_let] let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in (fun (input: parse_bounded_vldata_strong_t min max s) -> let pl = s32 input in let len = B32.len pl in assert (min <= U32.v len /\ U32.v len <= max); let slen = ser (len <: bounded_integer sz) in seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in res)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967292} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> s32: LowParse.SLow.Base.partial_serializer32 s -> input: LowParse.Spec.VLData.parse_bounded_vldata_strong_t min max s -> FStar.Pervasives.Lemma (ensures LowParse.SLow.Base.serializer32_correct (LowParse.Spec.VLData.serialize_bounded_vldata_strong' min max l s) input (LowParse.SLow.VLData.serialize32_bounded_vldata_strong_aux min max l s32 input))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.partial_serializer32", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "Prims._assert", "LowParse.SLow.Base.serializer32_correct", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong'", "LowParse.Spec.VLData.serialize_bounded_vldata_strong'", "Prims.unit", "Prims.eq2", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Bytes.reveal", "LowParse.Spec.VLData.serialize_bounded_vldata_strong_aux", "FStar.Bytes.byte", "FStar.Seq.Base.append", "LowParse.SLow.Base.bytes32", "LowParse.Bytes32.b32append", "LowParse.Spec.Combinators.seq_slice_append_r", "LowParse.Spec.Combinators.seq_slice_append_l", "LowParse.Spec.Base.serialize", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer", "LowParse.Spec.BoundedInt.serialize_bounded_integer", "FStar.UInt.uint_t", "FStar.UInt32.v", "FStar.UInt32.t", "FStar.Bytes.len", "LowParse.SLow.Base.serializer32", "LowParse.SLow.BoundedInt.serialize32_bounded_integer", "LowParse.Spec.BoundedInt.integer_size", "Prims.l_True", "Prims.squash", "LowParse.SLow.VLData.serialize32_bounded_vldata_strong_aux", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let serialize32_bounded_vldata_strong_correct (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) (input: parse_bounded_vldata_strong_t min max s) : Lemma (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input (serialize32_bounded_vldata_strong_aux min max l s32 input)) =
let sz:integer_size = l in let ser:serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in let pl = s32 input in assert (B32.reveal pl == s input); let len = B32.len pl in let nlen = U32.v len in assert (min <= nlen /\ nlen <= max); let slen = ser (len <: bounded_integer sz) in assert (B32.reveal slen == serialize (serialize_bounded_integer sz) len); seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res:bytes32 = B32.b32append slen pl in assert (B32.reveal res == Seq.append (B32.reveal slen) (B32.reveal pl)); assert (B32.reveal res == serialize_bounded_vldata_strong_aux min max l s input); assert (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res)
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.serialize32_bounded_vldata_strong_aux
val serialize32_bounded_vldata_strong_aux (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (parse_bounded_vldata_strong_t min max s -> Tot bytes32)
val serialize32_bounded_vldata_strong_aux (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (parse_bounded_vldata_strong_t min max s -> Tot bytes32)
let serialize32_bounded_vldata_strong_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (parse_bounded_vldata_strong_t min max s -> Tot bytes32) = [@inline_let] let sz : integer_size = l in [@inline_let] let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in (fun (input: parse_bounded_vldata_strong_t min max s) -> let pl = s32 input in let len = B32.len pl in assert (min <= U32.v len /\ U32.v len <= max); let slen = ser (len <: bounded_integer sz) in seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in res)
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 8, "end_line": 206, "start_col": 0, "start_line": 184 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input) inline_for_extraction let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32 inline_for_extraction let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1 : t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) let parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma ( let res : option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> () | Some (x, consumed) -> let x1 : t = x in let res = Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) in assert (parser32_correct (parse_bounded_vldata_strong' min max l s) input res) inline_for_extraction let parse32_bounded_vldata_strong' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s)) = make_parser32 (parse_bounded_vldata_strong' min max l s) (fun input -> parse32_bounded_vldata_strong_correct min min32 max max32 l s p32 input; parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input ) inline_for_extraction let parse32_bounded_vldata_strong (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong min max s)) = parse32_bounded_vldata_strong' min min32 max max32 (log256' max) s p32
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967292} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> s32: LowParse.SLow.Base.partial_serializer32 s -> _: LowParse.Spec.VLData.parse_bounded_vldata_strong_t min max s -> LowParse.SLow.Base.bytes32
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.partial_serializer32", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.SLow.Base.bytes32", "LowParse.Bytes32.b32append", "Prims.unit", "LowParse.Spec.Combinators.seq_slice_append_r", "FStar.Bytes.byte", "FStar.Bytes.reveal", "LowParse.Spec.Combinators.seq_slice_append_l", "LowParse.SLow.Base.serializer32_correct", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer", "LowParse.Spec.BoundedInt.serialize_bounded_integer", "Prims._assert", "FStar.UInt32.v", "FStar.UInt32.t", "FStar.Bytes.len", "LowParse.SLow.Base.serializer32", "LowParse.SLow.BoundedInt.serialize32_bounded_integer", "LowParse.Spec.BoundedInt.integer_size" ]
[]
false
false
false
false
false
let serialize32_bounded_vldata_strong_aux (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (parse_bounded_vldata_strong_t min max s -> Tot bytes32) =
[@@ inline_let ]let sz:integer_size = l in [@@ inline_let ]let ser:serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in (fun (input: parse_bounded_vldata_strong_t min max s) -> let pl = s32 input in let len = B32.len pl in assert (min <= U32.v len /\ U32.v len <= max); let slen = ser (len <: bounded_integer sz) in seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res:bytes32 = B32.b32append slen pl in res)
false
CustomSyntax.fst
CustomSyntax.zero
val zero:nat
val zero:nat
let zero : nat = 0
{ "file_name": "share/steel/examples/pulse/CustomSyntax.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 18, "end_line": 292, "start_col": 0, "start_line": 292 }
(* 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 } ``` let rec sum_spec (n:nat) : GTot nat = if n = 0 then 0 else n + sum_spec (n - 1) noextract
{ "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
Prims.nat
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let zero:nat =
0
false
Hacl.Streaming.Poly1305_32.fsti
Hacl.Streaming.Poly1305_32.malloc
val malloc : Hacl.Streaming.Functor.malloc_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 malloc = F.malloc (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": 17, "start_col": 0, "start_line": 17 }
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
{ "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.malloc_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.malloc", "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 malloc =
F.malloc (poly1305 M32) () (t M32) (poly1305_key.I.s ())
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.check_vldata_payload_size32
val check_vldata_payload_size32 (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967295}) (max32: U32.t{U32.v max32 == max}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (input: t) : Tot (y: bool{y == true <==> parse_bounded_vldata_strong_pred min max s input})
val check_vldata_payload_size32 (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967295}) (max32: U32.t{U32.v max32 == max}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (input: t) : Tot (y: bool{y == true <==> parse_bounded_vldata_strong_pred min max s input})
let check_vldata_payload_size32 (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967295 } ) // necessary to exclude the overflow case; enough to be compatible with serialize32 (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (input: t) : Tot (y: bool { y == true <==> parse_bounded_vldata_strong_pred min max s input } ) = let sz : U32.t = s32 input in [@inline_let] let y : bool = not (sz = u32_max || U32.lt sz min32 || U32.lt max32 sz) in [@inline_let] let _ : squash (y == true <==> parse_bounded_vldata_strong_pred min max s input) = if sz = u32_max then if Seq.length (serialize s input) > U32.v u32_max then () else begin assert (U32.v u32_max == Seq.length (serialize s input)); assert_norm (U32.v u32_max == 4294967295); assert (Seq.length (serialize s input) > max); assert (~ (parse_bounded_vldata_strong_pred min max s input)) end else if Seq.length (serialize s input) > U32.v u32_max then () else () in y
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 319, "start_col": 0, "start_line": 285 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input) inline_for_extraction let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32 inline_for_extraction let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1 : t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) let parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma ( let res : option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> () | Some (x, consumed) -> let x1 : t = x in let res = Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) in assert (parser32_correct (parse_bounded_vldata_strong' min max l s) input res) inline_for_extraction let parse32_bounded_vldata_strong' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s)) = make_parser32 (parse_bounded_vldata_strong' min max l s) (fun input -> parse32_bounded_vldata_strong_correct min min32 max max32 l s p32 input; parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input ) inline_for_extraction let parse32_bounded_vldata_strong (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong min max s)) = parse32_bounded_vldata_strong' min min32 max max32 (log256' max) s p32 inline_for_extraction let serialize32_bounded_vldata_strong_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (parse_bounded_vldata_strong_t min max s -> Tot bytes32) = [@inline_let] let sz : integer_size = l in [@inline_let] let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in (fun (input: parse_bounded_vldata_strong_t min max s) -> let pl = s32 input in let len = B32.len pl in assert (min <= U32.v len /\ U32.v len <= max); let slen = ser (len <: bounded_integer sz) in seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in res) let serialize32_bounded_vldata_strong_correct (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) (input: parse_bounded_vldata_strong_t min max s) : Lemma (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input (serialize32_bounded_vldata_strong_aux min max l s32 input)) = let sz : integer_size = l in let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in let pl = s32 input in assert (B32.reveal pl == s input); let len = B32.len pl in let nlen = U32.v len in assert (min <= nlen /\ nlen <= max); let slen = ser (len <: bounded_integer sz) in assert (B32.reveal slen == serialize (serialize_bounded_integer sz) len); seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in assert (B32.reveal res == Seq.append (B32.reveal slen) (B32.reveal pl)); assert (B32.reveal res == serialize_bounded_vldata_strong_aux min max l s input); assert (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res) inline_for_extraction let serialize32_bounded_vldata_strong' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong' min max l s)) = fun (input: parse_bounded_vldata_strong_t min max s) -> serialize32_bounded_vldata_strong_correct min max l s32 input; (serialize32_bounded_vldata_strong_aux min max l s32 input <: (res: bytes32 { serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res } )) inline_for_extraction let serialize32_bounded_vldata_strong (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong min max s)) = serialize32_bounded_vldata_strong' min max (log256' max) s32 inline_for_extraction let serialize32_bounded_vldata (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { serialize_bounded_vldata_precond min max k } ) : Tot (serializer32 (serialize_bounded_vldata min max s)) = fun (input: t) -> [@inline_let] let _ : unit = let Some (_, consumed) = parse p (serialize s input) in () in serialize32_bounded_vldata_strong_correct min max (log256' max) s32 input; (serialize32_bounded_vldata_strong_aux min max (log256' max) s32 input <: (res: bytes32 { serializer32_correct (serialize_bounded_vldata min max s) input res } )) #reset-options "--z3rlimit 32 --z3cliopt smt.arith.nl=false"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> min32: FStar.UInt32.t{FStar.UInt32.v min32 == min} -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967295} -> max32: FStar.UInt32.t{FStar.UInt32.v max32 == max} -> s32: LowParse.SLow.Base.size32 s -> input: t -> y: Prims.bool{y == true <==> LowParse.Spec.VLData.parse_bounded_vldata_strong_pred min max s input}
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.size32", "Prims.squash", "Prims.l_iff", "Prims.bool", "LowParse.Spec.VLData.parse_bounded_vldata_strong_pred", "Prims.op_Equality", "LowParse.SLow.Base.u32_max", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "LowParse.Spec.Base.serialize", "Prims._assert", "Prims.l_not", "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.op_Negation", "Prims.op_BarBar", "FStar.UInt32.lt" ]
[]
false
false
false
false
false
let check_vldata_payload_size32 (min: nat) (min32: U32.t{U32.v min32 == min}) (max: nat{min <= max /\ max > 0 /\ max < 4294967295}) (max32: U32.t{U32.v max32 == max}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (input: t) : Tot (y: bool{y == true <==> parse_bounded_vldata_strong_pred min max s input}) =
let sz:U32.t = s32 input in [@@ inline_let ]let y:bool = not (sz = u32_max || U32.lt sz min32 || U32.lt max32 sz) in [@@ inline_let ]let _:squash (y == true <==> parse_bounded_vldata_strong_pred min max s input) = if sz = u32_max then if Seq.length (serialize s input) > U32.v u32_max then () else (assert (U32.v u32_max == Seq.length (serialize s input)); assert_norm (U32.v u32_max == 4294967295); assert (Seq.length (serialize s input) > max); assert (~(parse_bounded_vldata_strong_pred min max s input))) else if Seq.length (serialize s input) > U32.v u32_max then () in y
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.size32_bounded_vldata
val size32_bounded_vldata (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s {serialize_bounded_vldata_precond min max k}) (sz32: U32.t{U32.v sz32 == log256' max}) : Tot (size32 (serialize_bounded_vldata min max s))
val size32_bounded_vldata (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s {serialize_bounded_vldata_precond min max k}) (sz32: U32.t{U32.v sz32 == log256' max}) : Tot (size32 (serialize_bounded_vldata min max s))
let size32_bounded_vldata (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s { serialize_bounded_vldata_precond min max k } ) (sz32: U32.t { U32.v sz32 == log256' max } ) : Tot (size32 (serialize_bounded_vldata min max s)) = fun (input: t) -> [@inline_let] let _ : unit = let Some (_, consumed) = parse p (serialize s input) in () in (size32_bounded_vldata_strong min max s32 sz32 input <: (res: U32.t { size32_postcond (serialize_bounded_vldata min max s) input res } ))
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 139, "end_line": 373, "start_col": 0, "start_line": 357 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input) inline_for_extraction let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32 inline_for_extraction let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1 : t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) let parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma ( let res : option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> () | Some (x, consumed) -> let x1 : t = x in let res = Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) in assert (parser32_correct (parse_bounded_vldata_strong' min max l s) input res) inline_for_extraction let parse32_bounded_vldata_strong' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s)) = make_parser32 (parse_bounded_vldata_strong' min max l s) (fun input -> parse32_bounded_vldata_strong_correct min min32 max max32 l s p32 input; parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input ) inline_for_extraction let parse32_bounded_vldata_strong (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong min max s)) = parse32_bounded_vldata_strong' min min32 max max32 (log256' max) s p32 inline_for_extraction let serialize32_bounded_vldata_strong_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (parse_bounded_vldata_strong_t min max s -> Tot bytes32) = [@inline_let] let sz : integer_size = l in [@inline_let] let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in (fun (input: parse_bounded_vldata_strong_t min max s) -> let pl = s32 input in let len = B32.len pl in assert (min <= U32.v len /\ U32.v len <= max); let slen = ser (len <: bounded_integer sz) in seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in res) let serialize32_bounded_vldata_strong_correct (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) (input: parse_bounded_vldata_strong_t min max s) : Lemma (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input (serialize32_bounded_vldata_strong_aux min max l s32 input)) = let sz : integer_size = l in let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in let pl = s32 input in assert (B32.reveal pl == s input); let len = B32.len pl in let nlen = U32.v len in assert (min <= nlen /\ nlen <= max); let slen = ser (len <: bounded_integer sz) in assert (B32.reveal slen == serialize (serialize_bounded_integer sz) len); seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in assert (B32.reveal res == Seq.append (B32.reveal slen) (B32.reveal pl)); assert (B32.reveal res == serialize_bounded_vldata_strong_aux min max l s input); assert (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res) inline_for_extraction let serialize32_bounded_vldata_strong' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong' min max l s)) = fun (input: parse_bounded_vldata_strong_t min max s) -> serialize32_bounded_vldata_strong_correct min max l s32 input; (serialize32_bounded_vldata_strong_aux min max l s32 input <: (res: bytes32 { serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res } )) inline_for_extraction let serialize32_bounded_vldata_strong (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong min max s)) = serialize32_bounded_vldata_strong' min max (log256' max) s32 inline_for_extraction let serialize32_bounded_vldata (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { serialize_bounded_vldata_precond min max k } ) : Tot (serializer32 (serialize_bounded_vldata min max s)) = fun (input: t) -> [@inline_let] let _ : unit = let Some (_, consumed) = parse p (serialize s input) in () in serialize32_bounded_vldata_strong_correct min max (log256' max) s32 input; (serialize32_bounded_vldata_strong_aux min max (log256' max) s32 input <: (res: bytes32 { serializer32_correct (serialize_bounded_vldata min max s) input res } )) #reset-options "--z3rlimit 32 --z3cliopt smt.arith.nl=false" inline_for_extraction let check_vldata_payload_size32 (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967295 } ) // necessary to exclude the overflow case; enough to be compatible with serialize32 (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (input: t) : Tot (y: bool { y == true <==> parse_bounded_vldata_strong_pred min max s input } ) = let sz : U32.t = s32 input in [@inline_let] let y : bool = not (sz = u32_max || U32.lt sz min32 || U32.lt max32 sz) in [@inline_let] let _ : squash (y == true <==> parse_bounded_vldata_strong_pred min max s input) = if sz = u32_max then if Seq.length (serialize s input) > U32.v u32_max then () else begin assert (U32.v u32_max == Seq.length (serialize s input)); assert_norm (U32.v u32_max == 4294967295); assert (Seq.length (serialize s input) > max); assert (~ (parse_bounded_vldata_strong_pred min max s input)) end else if Seq.length (serialize s input) > U32.v u32_max then () else () in y inline_for_extraction let size32_bounded_vldata_strong' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4, otherwise add overflows (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (sz32: U32.t { U32.v sz32 == l } ) : Tot (size32 (serialize_bounded_vldata_strong' min max l s)) = (fun (input: parse_bounded_vldata_strong_t min max s) -> let len = s32 input in [@inline_let] let _ = assert_norm (U32.v u32_max == 4294967295) in [@inline_let] let _ = assert (min <= U32.v len /\ U32.v len <= max) in [@inline_let] let res : U32.t = U32.add sz32 len in (res <: (res: U32.t { size32_postcond (serialize_bounded_vldata_strong' min max l s) input res } ))) inline_for_extraction let size32_bounded_vldata_strong (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4, otherwise add overflows (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (sz32: U32.t { U32.v sz32 == log256' max } ) : Tot (size32 (serialize_bounded_vldata_strong min max s)) = size32_bounded_vldata_strong' min max (log256' max) s32 sz32
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967292} -> s32: LowParse.SLow.Base.size32 s {LowParse.Spec.VLData.serialize_bounded_vldata_precond min max k} -> sz32: FStar.UInt32.t{FStar.UInt32.v sz32 == LowParse.Spec.BoundedInt.log256' max} -> LowParse.SLow.Base.size32 (LowParse.Spec.VLData.serialize_bounded_vldata min max s)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.size32", "LowParse.Spec.VLData.serialize_bounded_vldata_precond", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.op_GreaterThanOrEqual", "FStar.UInt32.v", "LowParse.Spec.BoundedInt.log256'", "LowParse.SLow.VLData.size32_bounded_vldata_strong", "LowParse.SLow.Base.size32_postcond", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.VLData.parse_bounded_vldata", "LowParse.Spec.VLData.serialize_bounded_vldata", "Prims.unit", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.serialize", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.parse" ]
[]
false
false
false
false
false
let size32_bounded_vldata (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s {serialize_bounded_vldata_precond min max k}) (sz32: U32.t{U32.v sz32 == log256' max}) : Tot (size32 (serialize_bounded_vldata min max s)) =
fun (input: t) -> [@@ inline_let ]let _:unit = let Some (_, consumed) = parse p (serialize s input) in () in (size32_bounded_vldata_strong min max s32 sz32 input <: (res: U32.t{size32_postcond (serialize_bounded_vldata min max s) input res}))
false
Hacl.Streaming.Poly1305_32.fsti
Hacl.Streaming.Poly1305_32.state_t
val state_t : Type0
let state_t = F.state_s (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": 71, "end_line": 13, "start_col": 0, "start_line": 13 }
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"
{ "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
Type0
Prims.Tot
[ "total" ]
[]
[ "Hacl.Streaming.Functor.state_s", "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
true
true
let state_t =
F.state_s (poly1305 M32) () (t M32) (poly1305_key.I.s ())
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_BitwiseXorCommutative
val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x)
val lemma_BitwiseXorCommutative (x y:nat32) : Lemma (x *^ y == y *^ x)
let lemma_BitwiseXorCommutative x y = lemma_ixor_nth_all 32; lemma_equal_nth 32 (x *^ y) (y *^ 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": 38, "end_line": 18, "start_col": 0, "start_line": 16 }
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))
{ "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.Words_s.nat32 -> y: Vale.Def.Words_s.nat32 -> FStar.Pervasives.Lemma (ensures x *^ y == y *^ x)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Words_s.nat32", "Vale.Arch.TypesNative.lemma_equal_nth", "Vale.Arch.Types.op_Star_Hat", "Prims.unit", "Vale.Arch.TypesNative.lemma_ixor_nth_all" ]
[]
true
false
true
false
false
let lemma_BitwiseXorCommutative x y =
lemma_ixor_nth_all 32; lemma_equal_nth 32 (x *^ y) (y *^ x)
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_nat_to_two32
val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
val lemma_nat_to_two32 (_:unit) : Lemma (forall (x:nat64).{:pattern (nat_to_two 32 x)} nat_to_two 32 x == Mktwo (x % 0x100000000) (x / 0x100000000))
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))
{ "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": 65, "end_line": 14, "start_col": 0, "start_line": 12 }
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
{ "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 (x: Vale.Def.Words_s.nat64). {:pattern Vale.Def.Words.Two_s.nat_to_two 32 x} Vale.Def.Words.Two_s.nat_to_two 32 x == Vale.Def.Words_s.Mktwo (x % 0x100000000) (x / 0x100000000))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.l_Forall", "Vale.Def.Words_s.nat64", "Prims.eq2", "Vale.Def.Words_s.two", "Vale.Def.Words_s.natN", "Prims.pow2", "Vale.Def.Words.Two_s.nat_to_two", "Vale.Def.Words_s.Mktwo", "Prims.op_Modulus", "Prims.op_Division" ]
[]
false
false
true
false
false
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))
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_BitwiseXorWithZero
val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n)
val lemma_BitwiseXorWithZero (n:nat32) : Lemma (n *^ 0 == n)
let lemma_BitwiseXorWithZero n = lemma_ixor_nth_all 32; lemma_zero_nth 32; lemma_equal_nth 32 (n *^ 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": 31, "end_line": 23, "start_col": 0, "start_line": 20 }
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)
{ "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
n: Vale.Def.Words_s.nat32 -> FStar.Pervasives.Lemma (ensures n *^ 0 == n)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Words_s.nat32", "Vale.Arch.TypesNative.lemma_equal_nth", "Vale.Arch.Types.op_Star_Hat", "Prims.unit", "Vale.Arch.TypesNative.lemma_zero_nth", "Vale.Arch.TypesNative.lemma_ixor_nth_all" ]
[]
true
false
true
false
false
let lemma_BitwiseXorWithZero n =
lemma_ixor_nth_all 32; lemma_zero_nth 32; lemma_equal_nth 32 (n *^ 0) n
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_BitwiseXorAssociative
val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z)
val lemma_BitwiseXorAssociative (x y z:nat32) : Lemma (x *^ (y *^ z) == (x *^ y) *^ z)
let lemma_BitwiseXorAssociative x y z = lemma_ixor_nth_all 32; lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
{ "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": 52, "end_line": 37, "start_col": 0, "start_line": 35 }
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
{ "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.Words_s.nat32 -> y: Vale.Def.Words_s.nat32 -> z: Vale.Def.Words_s.nat32 -> FStar.Pervasives.Lemma (ensures x *^ (y *^ z) == x *^ y *^ z)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Words_s.nat32", "Vale.Arch.TypesNative.lemma_equal_nth", "Vale.Arch.Types.op_Star_Hat", "Prims.unit", "Vale.Arch.TypesNative.lemma_ixor_nth_all" ]
[]
true
false
true
false
false
let lemma_BitwiseXorAssociative x y z =
lemma_ixor_nth_all 32; lemma_equal_nth 32 (x *^ (y *^ z)) ((x *^ y) *^ z)
false
SteelFramingTestSuite.fst
SteelFramingTestSuite.test_if4
val test_if4 (b: bool) : SteelT unit emp (fun _ -> emp)
val test_if4 (b: bool) : SteelT unit emp (fun _ -> emp)
let test_if4 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then (let r = alloc 0 in free r) else (noop ())
{ "file_name": "share/steel/tests/SteelFramingTestSuite.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 56, "end_line": 122, "start_col": 0, "start_line": 121 }
(* 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) // in the postcondition let test7 (_:unit) : SteelT ref emp ptr = let r = alloc 0 in let x = read r in write r 0; r let test8 (b1 b2 b3:ref) : SteelT unit (ptr b1 `star` ptr b2 `star` ptr b3) (fun _ -> ptr b2 `star` ptr b1 `star` ptr b3) = write b2 0 open Steel.Effect.Atomic let test_if1 (b:bool) : SteelT unit emp (fun _ -> emp) = if b then noop () else noop () let test_if2 (b:bool) (r: ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then write r 0 else write r 1 let test_if3 (b:bool) (r:ref) : SteelT unit (ptr r) (fun _ -> ptr r) = if b then noop () else noop ()
{ "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.Atomic", "short_module": null }, { "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
b: Prims.bool -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Prims.bool", "SteelFramingTestSuite.free", "Prims.unit", "SteelFramingTestSuite.ref", "SteelFramingTestSuite.alloc", "Steel.Effect.Atomic.noop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.emp", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let test_if4 (b: bool) : SteelT unit emp (fun _ -> emp) =
if b then (let r = alloc 0 in free r) else (noop ())
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_quad32_xor
val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0)
val lemma_quad32_xor (_:unit) : Lemma (forall q . {:pattern quad32_xor q q} quad32_xor q q == Mkfour 0 0 0 0)
let lemma_quad32_xor () = quad32_xor_reveal (); reverse_bytes_nat32_reveal (); xor_lemmas()
{ "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": 14, "end_line": 51, "start_col": 0, "start_line": 48 }
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; ()
{ "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 (q: Vale.Def.Types_s.quad32). {:pattern Vale.Def.Types_s.quad32_xor q q} Vale.Def.Types_s.quad32_xor q q == Vale.Def.Words_s.Mkfour 0 0 0 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "Vale.Arch.Types.xor_lemmas", "Vale.Def.Types_s.reverse_bytes_nat32_reveal", "Vale.Def.Types_s.quad32_xor_reveal" ]
[]
true
false
true
false
false
let lemma_quad32_xor () =
quad32_xor_reveal (); reverse_bytes_nat32_reveal (); xor_lemmas ()
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_BitwiseXorCancel64
val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor n n == 0)
val lemma_BitwiseXorCancel64 (n:nat64) : Lemma (ixor 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
{ "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": 33, "end_line": 33, "start_col": 0, "start_line": 30 }
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
{ "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
n: Vale.Def.Words_s.nat64 -> FStar.Pervasives.Lemma (ensures Vale.Def.Types_s.ixor n n == 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Words_s.nat64", "Vale.Arch.TypesNative.lemma_equal_nth", "Vale.Def.Types_s.ixor", "Vale.Def.Words_s.pow2_64", "Prims.unit", "Vale.Arch.TypesNative.lemma_zero_nth", "Vale.Arch.TypesNative.lemma_ixor_nth_all" ]
[]
true
false
true
false
false
let lemma_BitwiseXorCancel64 (n: nat64) =
lemma_ixor_nth_all 64; lemma_zero_nth 64; lemma_equal_nth 64 (ixor n n) 0
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_BitwiseXorCancel
val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0)
val lemma_BitwiseXorCancel (n:nat32) : Lemma (n *^ n == 0)
let lemma_BitwiseXorCancel n = lemma_ixor_nth_all 32; lemma_zero_nth 32; lemma_equal_nth 32 (n *^ n) 0
{ "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": 31, "end_line": 28, "start_col": 0, "start_line": 25 }
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
{ "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
n: Vale.Def.Words_s.nat32 -> FStar.Pervasives.Lemma (ensures n *^ n == 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Words_s.nat32", "Vale.Arch.TypesNative.lemma_equal_nth", "Vale.Arch.Types.op_Star_Hat", "Prims.unit", "Vale.Arch.TypesNative.lemma_zero_nth", "Vale.Arch.TypesNative.lemma_ixor_nth_all" ]
[]
true
false
true
false
false
let lemma_BitwiseXorCancel n =
lemma_ixor_nth_all 32; lemma_zero_nth 32; lemma_equal_nth 32 (n *^ n) 0
false
Hacl.Streaming.Poly1305_32.fsti
Hacl.Streaming.Poly1305_32.alloca
val alloca : Hacl.Streaming.Functor.alloca_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 alloca = F.alloca (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": 16, "start_col": 0, "start_line": 16 }
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 ())
{ "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.alloca_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.alloca", "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 alloca =
F.alloca (poly1305 M32) () (t M32) (poly1305_key.I.s ())
false
Vale.Arch.Types.fst
Vale.Arch.Types.xor_lemmas
val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} x *^ (y *^ z) == (x *^ y) *^ z) )
val xor_lemmas (_:unit) : Lemma (ensures (forall (x y:nat32).{:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n:nat32).{:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n:nat32).{:pattern (n *^ n)} n *^ n == 0) /\ (forall (n:nat64).{:pattern (ixor n n)} ixor n n == 0) /\ (forall (x y z:nat32).{:pattern (x *^ (y *^ z))} 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; ()
{ "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": 45, "start_col": 0, "start_line": 39 }
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)
{ "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 (x: Vale.Def.Words_s.nat32) (y: Vale.Def.Words_s.nat32). {:pattern (x *^ y)} x *^ y == y *^ x) /\ (forall (n: Vale.Def.Words_s.nat32). {:pattern (n *^ 0)} n *^ 0 == n) /\ (forall (n: Vale.Def.Words_s.nat32). {:pattern (n *^ n)} n *^ n == 0) /\ (forall (n: Vale.Def.Words_s.nat64). {:pattern Vale.Def.Types_s.ixor n n} Vale.Def.Types_s.ixor n n == 0) /\ (forall (x: Vale.Def.Words_s.nat32) (y: Vale.Def.Words_s.nat32) (z: Vale.Def.Words_s.nat32). {:pattern (x *^ (y *^ z))} x *^ (y *^ z) == x *^ y *^ z))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Classical.forall_intro_3", "Vale.Def.Words_s.nat32", "Prims.eq2", "Vale.Def.Types_s.nat32", "Vale.Arch.Types.op_Star_Hat", "Vale.Arch.Types.lemma_BitwiseXorAssociative", "FStar.Classical.forall_intro", "Vale.Def.Words_s.nat64", "Prims.int", "Vale.Def.Types_s.ixor", "Vale.Def.Words_s.pow2_64", "Vale.Arch.Types.lemma_BitwiseXorCancel64", "Vale.Arch.Types.lemma_BitwiseXorCancel", "Vale.Arch.Types.lemma_BitwiseXorWithZero", "FStar.Classical.forall_intro_2", "Vale.Arch.Types.lemma_BitwiseXorCommutative" ]
[]
false
false
true
false
false
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; ()
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_reverse_bytes_quad32
val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))]
val lemma_reverse_bytes_quad32 (q:quad32) : Lemma (reverse_bytes_quad32 (reverse_bytes_quad32 q) == q) [SMTPat (reverse_bytes_quad32 (reverse_bytes_quad32 q))]
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); ()
{ "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": 82, "start_col": 0, "start_line": 77 }
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; ()
{ "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
q: Vale.Def.Types_s.quad32 -> FStar.Pervasives.Lemma (ensures Vale.Def.Types_s.reverse_bytes_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 q) == q) [SMTPat (Vale.Def.Types_s.reverse_bytes_quad32 (Vale.Def.Types_s.reverse_bytes_quad32 q))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Types_s.quad32", "Prims.unit", "Vale.Def.Types_s.reveal_reverse_bytes_quad32", "Vale.Def.Types_s.reverse_bytes_quad32", "Vale.Def.Types_s.reverse_bytes_nat32_reveal", "Vale.Def.Types_s.quad32_xor_reveal" ]
[]
true
false
true
false
false
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); ()
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_reverse_bytes_quad32_zero
val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z)
val lemma_reverse_bytes_quad32_zero (_:unit) : Lemma (let z = Mkfour 0 0 0 0 in reverse_bytes_quad32 z == z)
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; }; ()
{ "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": 104, "start_col": 0, "start_line": 92 }
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); ()
{ "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 (let z = Vale.Def.Words_s.Mkfour 0 0 0 0 in Vale.Def.Types_s.reverse_bytes_quad32 z == z))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Calc.calc_finish", "Vale.Def.Types_s.quad32", "Prims.eq2", "Vale.Def.Types_s.reverse_bytes_quad32", "Prims.Cons", "FStar.Preorder.relation", "Prims.Nil", "FStar.Calc.calc_step", "Vale.Def.Words.Four_s.four_reverse", "Vale.Def.Types_s.nat32", "Vale.Def.Words.Four_s.four_map", "Vale.Def.Types_s.reverse_bytes_nat32", "FStar.Calc.calc_init", "FStar.Calc.calc_pack", "Vale.Def.Types_s.reveal_reverse_bytes_quad32", "Prims.squash", "Vale.Arch.Types.lemma_reverse_bytes_nat32", "Vale.Def.Words_s.four", "Vale.Def.Words_s.nat32", "Vale.Def.Words_s.Mkfour", "Prims.l_True", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
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; }; ()
false
Hacl.Streaming.Poly1305_32.fsti
Hacl.Streaming.Poly1305_32.reset
val reset : Hacl.Streaming.Functor.reset_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M32) (FStar.Ghost.hide (FStar.Ghost.reveal (FStar.Ghost.hide ()))) (Hacl.Streaming.Poly1305.t Hacl.Impl.Poly1305.Fields.M32) (Stateful?.s Hacl.Streaming.Poly1305.poly1305_key ())
let reset = F.reset (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": 76, "end_line": 18, "start_col": 0, "start_line": 18 }
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 ())
{ "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.reset_st (Hacl.Streaming.Poly1305.poly1305 Hacl.Impl.Poly1305.Fields.M32) (FStar.Ghost.hide (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.reset", "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 reset =
F.reset (poly1305 M32) (G.hide ()) (t M32) (poly1305_key.I.s ())
false
LowParse.SLow.VLData.fst
LowParse.SLow.VLData.size32_bounded_vldata_strong'
val size32_bounded_vldata_strong' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (sz32: U32.t{U32.v sz32 == l}) : Tot (size32 (serialize_bounded_vldata_strong' min max l s))
val size32_bounded_vldata_strong' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (sz32: U32.t{U32.v sz32 == l}) : Tot (size32 (serialize_bounded_vldata_strong' min max l s))
let size32_bounded_vldata_strong' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4, otherwise add overflows (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (sz32: U32.t { U32.v sz32 == l } ) : Tot (size32 (serialize_bounded_vldata_strong' min max l s)) = (fun (input: parse_bounded_vldata_strong_t min max s) -> let len = s32 input in [@inline_let] let _ = assert_norm (U32.v u32_max == 4294967295) in [@inline_let] let _ = assert (min <= U32.v len /\ U32.v len <= max) in [@inline_let] let res : U32.t = U32.add sz32 len in (res <: (res: U32.t { size32_postcond (serialize_bounded_vldata_strong' min max l s) input res } )))
{ "file_name": "src/lowparse/LowParse.SLow.VLData.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 105, "end_line": 341, "start_col": 0, "start_line": 322 }
module LowParse.SLow.VLData include LowParse.Spec.VLData include LowParse.SLow.FLData include LowParse.SLow.BoundedInt // for bounded_integer module Seq = FStar.Seq module U32 = FStar.UInt32 module B32 = LowParse.Bytes32 (* Parsers and serializers for the payload *) inline_for_extraction let parse32_vldata_payload (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) (i: bounded_integer sz { f i == true } ) : Tot (parser32 (parse_vldata_payload sz f p i)) = fun (input: bytes32) -> parse32_fldata p32 (U32.v i) i input inline_for_extraction let parse32_vldata_gen (sz: integer_size) (f: (bounded_integer sz -> GTot bool)) (f' : (x: bounded_integer sz) -> Tot (y: bool {y == f x})) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata_gen sz f p)) = [@inline_let] let _ = parse_vldata_gen_eq_def sz f p in parse32_and_then (parse32_filter (parse32_bounded_integer sz) f f') (parse_vldata_payload sz f p) () (parse32_vldata_payload sz f p32) inline_for_extraction let parse32_vldata (sz: integer_size) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_vldata sz p)) = parse32_vldata_gen sz (unconstrained_bounded_integer sz) (fun _ -> true) p32 #set-options "--z3rlimit 32" inline_for_extraction let parse32_bounded_vldata' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata' min max l p)) = [@inline_let] let _ = parse_bounded_vldata_correct min max l p in [@inline_let] let sz : integer_size = l in (fun input -> parse32_vldata_gen sz (in_bounds min max) (fun i -> not (U32.lt i min32 || U32.lt max32 i)) p32 input) inline_for_extraction let parse32_bounded_vldata (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (p32: parser32 p) : Tot (parser32 (parse_bounded_vldata min max p)) = parse32_bounded_vldata' min min32 max max32 (log256' max) p32 inline_for_extraction let parse32_bounded_vldata_strong_aux (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Tot (option (parse_bounded_vldata_strong_t min max #k #t #p s * U32.t)) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> None | Some (x, consumed) -> let x1 : t = x in Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) let parse32_bounded_vldata_strong_correct (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) (input: bytes32) : Lemma ( let res : option (parse_bounded_vldata_strong_t min max s * U32.t) = parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input in parser32_correct (parse_bounded_vldata_strong' min max l s) input res) = let res = parse32_strengthen #(parse_bounded_vldata_strong_kind min max l k) #t #(parse_bounded_vldata' min max l #k #t p) (parse32_bounded_vldata' min min32 max max32 l #k #t #p p32) (parse_bounded_vldata_strong_pred min max #k #t #p s) (parse_bounded_vldata_strong_correct min max l #k #t #p s) input in match res with | None -> () | Some (x, consumed) -> let x1 : t = x in let res = Some ((x1 <: parse_bounded_vldata_strong_t min max #k #t #p s), consumed) in assert (parser32_correct (parse_bounded_vldata_strong' min max l s) input res) inline_for_extraction let parse32_bounded_vldata_strong' (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong' min max l s)) = make_parser32 (parse_bounded_vldata_strong' min max l s) (fun input -> parse32_bounded_vldata_strong_correct min min32 max max32 l s p32 input; parse32_bounded_vldata_strong_aux min min32 max max32 l s p32 input ) inline_for_extraction let parse32_bounded_vldata_strong (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (s: serializer p) (p32: parser32 p) : Tot (parser32 #_ #(parse_bounded_vldata_strong_t min max s) (parse_bounded_vldata_strong min max s)) = parse32_bounded_vldata_strong' min min32 max max32 (log256' max) s p32 inline_for_extraction let serialize32_bounded_vldata_strong_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (parse_bounded_vldata_strong_t min max s -> Tot bytes32) = [@inline_let] let sz : integer_size = l in [@inline_let] let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in (fun (input: parse_bounded_vldata_strong_t min max s) -> let pl = s32 input in let len = B32.len pl in assert (min <= U32.v len /\ U32.v len <= max); let slen = ser (len <: bounded_integer sz) in seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in res) let serialize32_bounded_vldata_strong_correct (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) (input: parse_bounded_vldata_strong_t min max s) : Lemma (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input (serialize32_bounded_vldata_strong_aux min max l s32 input)) = let sz : integer_size = l in let ser : serializer32 (serialize_bounded_integer sz) = serialize32_bounded_integer sz in let pl = s32 input in assert (B32.reveal pl == s input); let len = B32.len pl in let nlen = U32.v len in assert (min <= nlen /\ nlen <= max); let slen = ser (len <: bounded_integer sz) in assert (B32.reveal slen == serialize (serialize_bounded_integer sz) len); seq_slice_append_l (B32.reveal slen) (B32.reveal pl); seq_slice_append_r (B32.reveal slen) (B32.reveal pl); let res : bytes32 = B32.b32append slen pl in assert (B32.reveal res == Seq.append (B32.reveal slen) (B32.reveal pl)); assert (B32.reveal res == serialize_bounded_vldata_strong_aux min max l s input); assert (serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res) inline_for_extraction let serialize32_bounded_vldata_strong' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (l: nat { l >= log256' max /\ l <= 4 } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong' min max l s)) = fun (input: parse_bounded_vldata_strong_t min max s) -> serialize32_bounded_vldata_strong_correct min max l s32 input; (serialize32_bounded_vldata_strong_aux min max l s32 input <: (res: bytes32 { serializer32_correct (serialize_bounded_vldata_strong' min max l s) input res } )) inline_for_extraction let serialize32_bounded_vldata_strong (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s) : Tot (serializer32 (serialize_bounded_vldata_strong min max s)) = serialize32_bounded_vldata_strong' min max (log256' max) s32 inline_for_extraction let serialize32_bounded_vldata (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967292 } ) // NOTE here: max must be less than 2^32 - 4 (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: partial_serializer32 s { serialize_bounded_vldata_precond min max k } ) : Tot (serializer32 (serialize_bounded_vldata min max s)) = fun (input: t) -> [@inline_let] let _ : unit = let Some (_, consumed) = parse p (serialize s input) in () in serialize32_bounded_vldata_strong_correct min max (log256' max) s32 input; (serialize32_bounded_vldata_strong_aux min max (log256' max) s32 input <: (res: bytes32 { serializer32_correct (serialize_bounded_vldata min max s) input res } )) #reset-options "--z3rlimit 32 --z3cliopt smt.arith.nl=false" inline_for_extraction let check_vldata_payload_size32 (min: nat) (min32: U32.t { U32.v min32 == min } ) (max: nat { min <= max /\ max > 0 /\ max < 4294967295 } ) // necessary to exclude the overflow case; enough to be compatible with serialize32 (max32: U32.t { U32.v max32 == max } ) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (input: t) : Tot (y: bool { y == true <==> parse_bounded_vldata_strong_pred min max s input } ) = let sz : U32.t = s32 input in [@inline_let] let y : bool = not (sz = u32_max || U32.lt sz min32 || U32.lt max32 sz) in [@inline_let] let _ : squash (y == true <==> parse_bounded_vldata_strong_pred min max s input) = if sz = u32_max then if Seq.length (serialize s input) > U32.v u32_max then () else begin assert (U32.v u32_max == Seq.length (serialize s input)); assert_norm (U32.v u32_max == 4294967295); assert (Seq.length (serialize s input) > max); assert (~ (parse_bounded_vldata_strong_pred min max s input)) end else if Seq.length (serialize s input) > U32.v u32_max then () else () in y
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.VLData.fsti.checked", "LowParse.SLow.FLData.fst.checked", "LowParse.SLow.BoundedInt.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "LowParse.SLow.VLData.fst" }
[ { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "B32" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": false, "full_module": "LowParse.SLow.BoundedInt", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow.FLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "LowParse.SLow", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "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": [ "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967292} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> s32: LowParse.SLow.Base.size32 s -> sz32: FStar.UInt32.t{FStar.UInt32.v sz32 == l} -> LowParse.SLow.Base.size32 (LowParse.Spec.VLData.serialize_bounded_vldata_strong' min max l s)
Prims.Tot
[ "total" ]
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "LowParse.SLow.Base.size32", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "FStar.UInt32.v", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.SLow.Base.size32_postcond", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong'", "LowParse.Spec.VLData.serialize_bounded_vldata_strong'", "FStar.UInt32.add", "Prims.unit", "Prims._assert", "FStar.Pervasives.assert_norm", "LowParse.SLow.Base.u32_max" ]
[]
false
false
false
false
false
let size32_bounded_vldata_strong' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967292}) (l: nat{l >= log256' max /\ l <= 4}) (#k: parser_kind) (#t: Type) (#p: parser k t) (#s: serializer p) (s32: size32 s) (sz32: U32.t{U32.v sz32 == l}) : Tot (size32 (serialize_bounded_vldata_strong' min max l s)) =
(fun (input: parse_bounded_vldata_strong_t min max s) -> let len = s32 input in [@@ inline_let ]let _ = assert_norm (U32.v u32_max == 4294967295) in [@@ inline_let ]let _ = assert (min <= U32.v len /\ U32.v len <= max) in [@@ inline_let ]let res:U32.t = U32.add sz32 len in (res <: (res: U32.t{size32_postcond (serialize_bounded_vldata_strong' min max l s) input res})))
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_reverse_reverse_bytes_nat32_seq
val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))]
val lemma_reverse_reverse_bytes_nat32_seq (s:seq nat32) : Lemma (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s) == s) [SMTPat (reverse_bytes_nat32_seq (reverse_bytes_nat32_seq s))]
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)
{ "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": 72, "end_line": 111, "start_col": 0, "start_line": 106 }
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; }; ()
{ "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
s: FStar.Seq.Base.seq Vale.Def.Words_s.nat32 -> FStar.Pervasives.Lemma (ensures Vale.Def.Types_s.reverse_bytes_nat32_seq (Vale.Def.Types_s.reverse_bytes_nat32_seq s) == s) [ SMTPat (Vale.Def.Types_s.reverse_bytes_nat32_seq (Vale.Def.Types_s.reverse_bytes_nat32_seq s )) ]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat32", "Prims._assert", "FStar.Seq.Base.equal", "Vale.Def.Types_s.nat32", "Vale.Def.Types_s.reverse_bytes_nat32_seq", "Prims.unit", "Vale.Def.Types_s.reveal_reverse_bytes_nat32_seq", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
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)
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_lo64_properties
val lemma_lo64_properties (_:unit) : Lemma (forall (q0 q1:quad32).{:pattern lo64 q0; lo64 q1} (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
val lemma_lo64_properties (_:unit) : Lemma (forall (q0 q1:quad32).{:pattern lo64 q0; lo64 q1} (q0.lo0 == q1.lo0 /\ q0.lo1 == q1.lo1) <==> (lo64 q0 == lo64 q1))
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; ()
{ "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": 179, "start_col": 0, "start_line": 167 }
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 (); ()
{ "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.lo64 q0; Vale.Arch.Types.lo64 q1} Mkfour?.lo0 q0 == Mkfour?.lo0 q1 /\ Mkfour?.lo1 q0 == Mkfour?.lo1 q1 <==> Vale.Arch.Types.lo64 q0 == Vale.Arch.Types.lo64 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__lo0", "Vale.Def.Words_s.__proj__Mkfour__item__lo1", "Vale.Def.Words_s.nat64", "Vale.Arch.Types.lo64", "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.lo64_reveal", "Prims.l_Forall" ]
[]
false
false
true
false
false
let lemma_lo64_properties (_: unit) : Lemma (forall (q0: quad32) (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; ()
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_reverse_bytes_nat32
val lemma_reverse_bytes_nat32: unit -> Lemma (reverse_bytes_nat32 0 == 0)
val lemma_reverse_bytes_nat32: unit -> Lemma (reverse_bytes_nat32 0 == 0)
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); ()
{ "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": 90, "start_col": 0, "start_line": 85 }
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
{ "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.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "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.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 Vale.Def.Types_s.reverse_bytes_nat32 0 == 0)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Pervasives.assert_norm", "Prims.eq2", "Vale.Def.Words_s.four", "Vale.Def.Words_s.natN", "Prims.pow2", "Vale.Def.Words.Four_s.nat_to_four", "Vale.Def.Words_s.Mkfour", "Vale.Def.Types_s.reverse_bytes_nat32_reveal", "Prims.l_True", "Prims.squash", "Prims.int", "Vale.Def.Types_s.reverse_bytes_nat32", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
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); ()
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_reverse_reverse_bytes_nat32
val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))]
val lemma_reverse_reverse_bytes_nat32 (n:nat32) : Lemma (reverse_bytes_nat32 (reverse_bytes_nat32 n) == n) [SMTPat (reverse_bytes_nat32 (reverse_bytes_nat32 n))]
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; ()
{ "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": 74, "start_col": 0, "start_line": 68 }
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
{ "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
n: Vale.Def.Words_s.nat32 -> FStar.Pervasives.Lemma (ensures Vale.Def.Types_s.reverse_bytes_nat32 (Vale.Def.Types_s.reverse_bytes_nat32 n) == n) [SMTPat (Vale.Def.Types_s.reverse_bytes_nat32 (Vale.Def.Types_s.reverse_bytes_nat32 n))]
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Words_s.nat32", "Prims.unit", "Vale.Def.Types_s.be_bytes_to_nat32_to_be_bytes", "FStar.Seq.Base.seq", "Vale.Def.Words_s.nat8", "Vale.Lib.Seqs_s.reverse_seq", "Vale.Def.Types_s.nat8", "Vale.Def.Types_s.nat32_to_be_bytes", "Vale.Def.Types_s.reverse_bytes_nat32_reveal", "Prims.l_True", "Prims.squash", "Prims.eq2", "Vale.Def.Types_s.reverse_bytes_nat32", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
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; ()
false
Vale.Arch.Types.fst
Vale.Arch.Types.lemma_reverse_bytes_nat64_32
val 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)))
val 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)))
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 ()
{ "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": 31, "end_line": 198, "start_col": 0, "start_line": 195 }
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; ()
{ "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.Def.Words_s", "short_module": null }, { "abbrev": false, "full_module": "Vale.Lib.Seqs", "short_module": null }, { "abbrev": false, "full_module": "Vale.Arch.TypesNative", "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.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
n0: Vale.Def.Words_s.nat32 -> n1: Vale.Def.Words_s.nat32 -> FStar.Pervasives.Lemma (ensures Vale.Def.Types_s.reverse_bytes_nat64 (Vale.Arch.Types.two_to_nat32 (Vale.Def.Words_s.Mktwo n0 n1)) == Vale.Arch.Types.two_to_nat32 (Vale.Def.Words_s.Mktwo (Vale.Def.Types_s.reverse_bytes_nat32 n1) (Vale.Def.Types_s.reverse_bytes_nat32 n0)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Vale.Def.Words_s.nat32", "Vale.Def.Types_s.reverse_bytes_nat64_reveal", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Vale.Def.Words_s.nat64", "Vale.Def.Types_s.reverse_bytes_nat64", "Vale.Arch.Types.two_to_nat32", "Vale.Def.Words_s.Mktwo", "Vale.Def.Types_s.reverse_bytes_nat32", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
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 ()
false