effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prims.Tot | val logxor: #t:inttype -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b | val logxor: #t:inttype -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l
let logxor #t #l a b = | false | null | false | match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"total"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.UInt8.logxor",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.UInt8.t",
"FStar.UInt8.__uint_to_t",
"FStar.UInt16.logxor",
"FStar.UInt32.logxor",
"FStar.UInt64.logxor",
"FStar.UInt128.logxor",
"FStar.Int8.logxor",
"FStar.Int16.logxor",
"FStar.Int32.logxor",
"FStar.Int64.logxor",
"FStar.Int128.logxor"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])] | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logxor: #t:inttype -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l | [] | Lib.IntTypes.logxor | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l -> Lib.IntTypes.int_t t l | {
"end_col": 29,
"end_line": 434,
"start_col": 2,
"start_line": 418
} |
Prims.Tot | val ct_abs: #t:inttype{signed t /\ ~(S128? t)} -> #l:secrecy_level
-> a:int_t t l{minint t < v a}
-> b:int_t t l{v b == abs (v a)} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a | val ct_abs: #t:inttype{signed t /\ ~(S128? t)} -> #l:secrecy_level
-> a:int_t t l{minint t < v a}
-> b:int_t t l{v b == abs (v a)}
let ct_abs #t #l a = | false | null | false | match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"total"
] | [
"Lib.IntTypes.inttype",
"Prims.l_and",
"Prims.b2t",
"Lib.IntTypes.signed",
"Prims.l_not",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Prims.op_LessThan",
"Lib.IntTypes.minint",
"Lib.IntTypes.v",
"FStar.Int8.ct_abs",
"FStar.Int16.ct_abs",
"FStar.Int32.ct_abs",
"FStar.Int64.ct_abs",
"Prims.eq2",
"Prims.int",
"Prims.abs"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])] | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ct_abs: #t:inttype{signed t /\ ~(S128? t)} -> #l:secrecy_level
-> a:int_t t l{minint t < v a}
-> b:int_t t l{v b == abs (v a)} | [] | Lib.IntTypes.ct_abs | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t l {Lib.IntTypes.minint t < Lib.IntTypes.v a}
-> b: Lib.IntTypes.int_t t l {Lib.IntTypes.v b == Prims.abs (Lib.IntTypes.v a)} | {
"end_col": 25,
"end_line": 786,
"start_col": 2,
"start_line": 782
} |
Prims.Tot | val rotate_right: #t:inttype -> #l:secrecy_level
-> a:int_t t l{unsigned t}
-> rotval t
-> int_t t l | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b)) | val rotate_right: #t:inttype -> #l:secrecy_level
-> a:int_t t l{unsigned t}
-> rotval t
-> int_t t l
let rotate_right #t #l a b = | false | null | false | logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b)) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"total"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.rotval",
"Lib.IntTypes.logor",
"Lib.IntTypes.shift_right",
"Lib.IntTypes.shift_left",
"Lib.IntTypes.sub",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.size",
"Lib.IntTypes.bits"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = () | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rotate_right: #t:inttype -> #l:secrecy_level
-> a:int_t t l{unsigned t}
-> rotval t
-> int_t t l | [] | Lib.IntTypes.rotate_right | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t l {Lib.IntTypes.unsigned t} -> b: Lib.IntTypes.rotval t
-> Lib.IntTypes.int_t t l | {
"end_col": 69,
"end_line": 775,
"start_col": 2,
"start_line": 775
} |
FStar.Pervasives.Lemma | val logand_ones: #t:inttype -> #l:secrecy_level -> a:int_t t l ->
Lemma (v (a `logand` ones t l) == v a) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a) | val logand_ones: #t:inttype -> #l:secrecy_level -> a:int_t t l ->
Lemma (v (a `logand` ones t l) == v a)
let logand_ones #t #l a = | false | null | true | match t with
| U1 -> assert_norm ((u1 0) `logand` (ones U1 l) == u1 0 /\ (u1 1) `logand` (ones U1 l) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.Pervasives.assert_norm",
"Prims.l_and",
"Prims.eq2",
"Lib.IntTypes.U1",
"Lib.IntTypes.SEC",
"Lib.IntTypes.logand",
"Lib.IntTypes.u1",
"Lib.IntTypes.ones",
"FStar.UInt.logand_lemma_2",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"FStar.Int.logand_lemma_2",
"Prims.unit"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a) | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logand_ones: #t:inttype -> #l:secrecy_level -> a:int_t t l ->
Lemma (v (a `logand` ones t l) == v a) | [] | Lib.IntTypes.logand_ones | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma
(ensures Lib.IntTypes.v (Lib.IntTypes.logand a (Lib.IntTypes.ones t l)) == Lib.IntTypes.v a) | {
"end_col": 69,
"end_line": 521,
"start_col": 2,
"start_line": 518
} |
FStar.Pervasives.Lemma | val logor_zeros: #t: inttype -> #l: secrecy_level -> a: int_t t l ->
Lemma (v (a `logor` zeros t l) == v a) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a) | val logor_zeros: #t: inttype -> #l: secrecy_level -> a: int_t t l ->
Lemma (v (a `logor` zeros t l) == v a)
let logor_zeros #t #l a = | false | null | true | match t with
| U1 -> assert_norm ((u1 0) `logor` (zeros U1 l) == u1 0 /\ (u1 1) `logor` (zeros U1 l) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8
| S16
| S32
| S64
| S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.Pervasives.assert_norm",
"Prims.l_and",
"Prims.eq2",
"Lib.IntTypes.U1",
"Lib.IntTypes.SEC",
"Lib.IntTypes.logor",
"Lib.IntTypes.u1",
"Lib.IntTypes.zeros",
"FStar.UInt.logor_lemma_1",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"FStar.Int.nth_lemma",
"FStar.Int.logor",
"FStar.Int.zero",
"Prims.unit"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logor_zeros: #t: inttype -> #l: secrecy_level -> a: int_t t l ->
Lemma (v (a `logor` zeros t l) == v a) | [] | Lib.IntTypes.logor_zeros | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma
(ensures Lib.IntTypes.v (Lib.IntTypes.logor a (Lib.IntTypes.zeros t l)) == Lib.IntTypes.v a) | {
"end_col": 112,
"end_line": 609,
"start_col": 2,
"start_line": 606
} |
Prims.Pure | val shift_left: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> s:shiftval t
-> Pure (int_t t l)
(requires unsigned t \/ (0 <= v a /\ v a * pow2 (v s) <= maxint t))
(ensures fun _ -> True) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b | val shift_left: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> s:shiftval t
-> Pure (int_t t l)
(requires unsigned t \/ (0 <= v a /\ v a * pow2 (v s) <= maxint t))
(ensures fun _ -> True)
let shift_left #t #l a b = | false | null | false | match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Lib.IntTypes.shiftval",
"FStar.UInt8.shift_left",
"FStar.UInt16.shift_left",
"FStar.UInt32.shift_left",
"FStar.UInt64.shift_left",
"FStar.UInt128.shift_left",
"FStar.Int8.shift_left",
"FStar.Int16.shift_left",
"FStar.Int32.shift_left",
"FStar.Int64.shift_left",
"FStar.Int128.shift_left"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])] | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shift_left: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> s:shiftval t
-> Pure (int_t t l)
(requires unsigned t \/ (0 <= v a /\ v a * pow2 (v s) <= maxint t))
(ensures fun _ -> True) | [] | Lib.IntTypes.shift_left | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t l -> s: Lib.IntTypes.shiftval t -> Prims.Pure (Lib.IntTypes.int_t t l) | {
"end_col": 33,
"end_line": 768,
"start_col": 2,
"start_line": 757
} |
FStar.Pervasives.Lemma | val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b) | val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b = | false | null | true | match t with
| U1
| U8
| U16
| U32
| U64
| U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8
| S16
| S32
| S64
| S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.UInt.logxor_lemma_1",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"Prims.unit",
"FStar.UInt.logxor_commutative",
"FStar.UInt.logxor_self",
"FStar.UInt.logxor_associative",
"FStar.Int.logxor_lemma_1",
"FStar.Int.logxor_commutative",
"FStar.Int.logxor_self",
"FStar.Int.logxor_associative"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b) | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b) | [] | Lib.IntTypes.logxor_lemma_ | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma
(ensures Lib.IntTypes.v (Lib.IntTypes.logxor a (Lib.IntTypes.logxor a b)) == Lib.IntTypes.v b) | {
"end_col": 38,
"end_line": 451,
"start_col": 2,
"start_line": 441
} |
Prims.Tot | val gt_mask: #t:inttype{unsigned t} -> int_t t SEC -> b:int_t t SEC -> int_t t SEC | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b) | val gt_mask: #t:inttype{unsigned t} -> int_t t SEC -> b:int_t t SEC -> int_t t SEC
let gt_mask #t a b = | false | null | false | logand (gte_mask a b) (neq_mask a b) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"total"
] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.logand",
"Lib.IntTypes.gte_mask",
"Lib.IntTypes.neq_mask"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0 | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gt_mask: #t:inttype{unsigned t} -> int_t t SEC -> b:int_t t SEC -> int_t t SEC | [] | Lib.IntTypes.gt_mask | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t Lib.IntTypes.SEC -> b: Lib.IntTypes.int_t t Lib.IntTypes.SEC
-> Lib.IntTypes.int_t t Lib.IntTypes.SEC | {
"end_col": 57,
"end_line": 925,
"start_col": 21,
"start_line": 925
} |
FStar.Pervasives.Lemma | val eq_mask_logand_lemma:
#t:inttype{~(S128? t)}
-> a:int_t t SEC
-> b:int_t t SEC
-> c:int_t t SEC -> Lemma
(if v a = v b then v (c `logand` eq_mask a b) == v c
else v (c `logand` eq_mask a b) == 0)
[SMTPat (c `logand` eq_mask a b)] | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c) | val eq_mask_logand_lemma:
#t:inttype{~(S128? t)}
-> a:int_t t SEC
-> b:int_t t SEC
-> c:int_t t SEC -> Lemma
(if v a = v b then v (c `logand` eq_mask a b) == v c
else v (c `logand` eq_mask a b) == 0)
[SMTPat (c `logand` eq_mask a b)]
let eq_mask_logand_lemma #t a b c = | false | null | true | eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"FStar.UInt.logand_commutative",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"Lib.IntTypes.eq_mask",
"FStar.Int.logand_commutative",
"Prims.unit",
"Lib.IntTypes.logand_ones",
"Lib.IntTypes.logand_zeros",
"Lib.IntTypes.eq_mask_lemma"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eq_mask_logand_lemma:
#t:inttype{~(S128? t)}
-> a:int_t t SEC
-> b:int_t t SEC
-> c:int_t t SEC -> Lemma
(if v a = v b then v (c `logand` eq_mask a b) == v c
else v (c `logand` eq_mask a b) == 0)
[SMTPat (c `logand` eq_mask a b)] | [] | Lib.IntTypes.eq_mask_logand_lemma | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Lib.IntTypes.int_t t Lib.IntTypes.SEC ->
b: Lib.IntTypes.int_t t Lib.IntTypes.SEC ->
c: Lib.IntTypes.int_t t Lib.IntTypes.SEC
-> FStar.Pervasives.Lemma
(ensures
((match Lib.IntTypes.v a = Lib.IntTypes.v b with
| true ->
Lib.IntTypes.v (Lib.IntTypes.logand c (Lib.IntTypes.eq_mask a b)) == Lib.IntTypes.v c
| _ -> Lib.IntTypes.v (Lib.IntTypes.logand c (Lib.IntTypes.eq_mask a b)) == 0)
<:
Type0)) [SMTPat (Lib.IntTypes.logand c (Lib.IntTypes.eq_mask a b))] | {
"end_col": 84,
"end_line": 874,
"start_col": 2,
"start_line": 869
} |
Prims.Tot | val lte_mask: #t:inttype{unsigned t} -> int_t t SEC -> int_t t SEC -> int_t t SEC | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b) | val lte_mask: #t:inttype{unsigned t} -> int_t t SEC -> int_t t SEC -> int_t t SEC
let lte_mask #t a b = | false | null | false | logor (lt_mask a b) (eq_mask a b) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"total"
] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.logor",
"Lib.IntTypes.lt_mask",
"Lib.IntTypes.eq_mask"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b) | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lte_mask: #t:inttype{unsigned t} -> int_t t SEC -> int_t t SEC -> int_t t SEC | [] | Lib.IntTypes.lte_mask | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t Lib.IntTypes.SEC -> b: Lib.IntTypes.int_t t Lib.IntTypes.SEC
-> Lib.IntTypes.int_t t Lib.IntTypes.SEC | {
"end_col": 55,
"end_line": 931,
"start_col": 22,
"start_line": 931
} |
FStar.Pervasives.Lemma | val shift_right_lemma: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:shiftval t
-> Lemma
(v (shift_right a b) == v a / pow2 (v b))
[SMTPat (v #t #l (shift_right #t #l a b))] | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b) | val shift_right_lemma: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:shiftval t
-> Lemma
(v (shift_right a b) == v a / pow2 (v b))
[SMTPat (v #t #l (shift_right #t #l a b))]
let shift_right_lemma #t #l a b = | false | null | true | match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8
| S16
| S32
| S64
| S128 ->
if v b = 0
then ()
else
if v b >= bits t
then shift_right_value_aux_1 #(bits t) (v a) (v b)
else shift_right_value_aux_3 #(bits t) (v a) (v b) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Lib.IntTypes.shiftval",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.bool",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.bits",
"Lib.IntTypes.shift_right_value_aux_1",
"Lib.IntTypes.shift_right_value_aux_3",
"Prims.unit"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shift_right_lemma: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:shiftval t
-> Lemma
(v (shift_right a b) == v a / pow2 (v b))
[SMTPat (v #t #l (shift_right #t #l a b))] | [] | Lib.IntTypes.shift_right_lemma | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.shiftval t
-> FStar.Pervasives.Lemma
(ensures
Lib.IntTypes.v (Lib.IntTypes.shift_right a b) ==
Lib.IntTypes.v a / Prims.pow2 (Lib.IntTypes.v b))
[SMTPat (Lib.IntTypes.v (Lib.IntTypes.shift_right a b))] | {
"end_col": 51,
"end_line": 753,
"start_col": 2,
"start_line": 746
} |
FStar.Pervasives.Lemma | val logor_lemma: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a = 0 \/ v a = ones_v t)
(ensures (if v a = ones_v t then v (a `logor` b) == ones_v t else v (a `logor` b) == v b)) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a)) | val logor_lemma: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a = 0 \/ v a = ones_v t)
(ensures (if v a = ones_v t then v (a `logor` b) == ones_v t else v (a `logor` b) == v b))
let logor_lemma #t #l a b = | false | null | true | logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm ((u1 0) `logor` (ones U1 l) == u1 1 /\ (u1 1) `logor` (ones U1 l) == u1 1);
assert_norm ((u1 0) `logor` (zeros U1 l) == u1 0 /\ (u1 1) `logor` (zeros U1 l) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8
| S16
| S32
| S64
| S128 ->
Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a)) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.Pervasives.assert_norm",
"Prims.l_and",
"Prims.eq2",
"Lib.IntTypes.U1",
"Lib.IntTypes.SEC",
"Lib.IntTypes.logor",
"Lib.IntTypes.u1",
"Lib.IntTypes.zeros",
"Prims.unit",
"Lib.IntTypes.ones",
"FStar.UInt.logor_commutative",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"FStar.Int.nth_lemma",
"FStar.Int.logor",
"Lib.IntTypes.logor_ones",
"Lib.IntTypes.logor_zeros"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t)) | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logor_lemma: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a = 0 \/ v a = ones_v t)
(ensures (if v a = ones_v t then v (a `logor` b) == ones_v t else v (a `logor` b) == v b)) | [] | Lib.IntTypes.logor_lemma | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma
(requires Lib.IntTypes.v a = 0 \/ Lib.IntTypes.v a = Lib.IntTypes.ones_v t)
(ensures
((match Lib.IntTypes.v a = Lib.IntTypes.ones_v t with
| true -> Lib.IntTypes.v (Lib.IntTypes.logor a b) == Lib.IntTypes.ones_v t
| _ -> Lib.IntTypes.v (Lib.IntTypes.logor a b) == Lib.IntTypes.v b)
<:
Type0)) | {
"end_col": 126,
"end_line": 626,
"start_col": 2,
"start_line": 619
} |
FStar.Pervasives.Lemma | val logand_le:#t:inttype{unsigned t} -> #l:secrecy_level -> a:uint_t t l -> b:uint_t t l ->
Lemma (requires True)
(ensures v (logand a b) <= v a /\ v (logand a b) <= v b) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b)) | val logand_le:#t:inttype{unsigned t} -> #l:secrecy_level -> a:uint_t t l -> b:uint_t t l ->
Lemma (requires True)
(ensures v (logand a b) <= v a /\ v (logand a b) <= v b)
let logand_le #t #l a b = | false | null | true | match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b)) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.uint_t",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.UInt8.t",
"FStar.UInt8.logand",
"FStar.UInt8.__uint_to_t",
"Prims.unit",
"FStar.UInt.logand_le",
"FStar.UInt.to_uint_t",
"Lib.IntTypes.v"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> () | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logand_le:#t:inttype{unsigned t} -> #l:secrecy_level -> a:uint_t t l -> b:uint_t t l ->
Lemma (requires True)
(ensures v (logand a b) <= v a /\ v (logand a b) <= v b) | [] | Lib.IntTypes.logand_le | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.uint_t t l -> b: Lib.IntTypes.uint_t t l
-> FStar.Pervasives.Lemma
(ensures
Lib.IntTypes.v (Lib.IntTypes.logand a b) <= Lib.IntTypes.v a /\
Lib.IntTypes.v (Lib.IntTypes.logand a b) <= Lib.IntTypes.v b) | {
"end_col": 80,
"end_line": 553,
"start_col": 2,
"start_line": 543
} |
FStar.Pervasives.Lemma | val gte_mask_lemma: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a >= v b then v (gte_mask a b) == ones_v t
else v (gte_mask a b) == 0)
[SMTPat (gte_mask #t a b)] | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> () | val gte_mask_lemma: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a >= v b then v (gte_mask a b) == ones_v t
else v (gte_mask a b) == 0)
[SMTPat (gte_mask #t a b)]
let gte_mask_lemma #t a b = | false | null | true | match t with
| U1 ->
assert_norm (logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\ lognot (u1 1) == u1 0 /\
lognot (u1 0) == u1 1)
| _ -> () | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"FStar.Pervasives.assert_norm",
"Prims.l_and",
"Prims.eq2",
"Lib.IntTypes.U1",
"Lib.IntTypes.logor",
"Lib.IntTypes.u1",
"Lib.IntTypes.lognot",
"Prims.unit"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gte_mask_lemma: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a >= v b then v (gte_mask a b) == ones_v t
else v (gte_mask a b) == 0)
[SMTPat (gte_mask #t a b)] | [] | Lib.IntTypes.gte_mask_lemma | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t Lib.IntTypes.SEC -> b: Lib.IntTypes.int_t t Lib.IntTypes.SEC
-> FStar.Pervasives.Lemma
(ensures
((match Lib.IntTypes.v a >= Lib.IntTypes.v b with
| true -> Lib.IntTypes.v (Lib.IntTypes.gte_mask a b) == Lib.IntTypes.ones_v t
| _ -> Lib.IntTypes.v (Lib.IntTypes.gte_mask a b) == 0)
<:
Type0)) [SMTPat (Lib.IntTypes.gte_mask a b)] | {
"end_col": 11,
"end_line": 905,
"start_col": 2,
"start_line": 897
} |
FStar.Pervasives.Lemma | val gt_mask_lemma: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a > v b then v (gt_mask a b) == ones_v t
else v (gt_mask a b) == 0)
[SMTPat (gt_mask #t a b)] | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b) | val gt_mask_lemma: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a > v b then v (gt_mask a b) == ones_v t
else v (gt_mask a b) == 0)
[SMTPat (gt_mask #t a b)]
let gt_mask_lemma #t a b = | false | null | true | logand_zeros (gte_mask a b);
logand_ones (gte_mask a b) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.logand_ones",
"Lib.IntTypes.gte_mask",
"Prims.unit",
"Lib.IntTypes.logand_zeros"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b) | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gt_mask_lemma: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a > v b then v (gt_mask a b) == ones_v t
else v (gt_mask a b) == 0)
[SMTPat (gt_mask #t a b)] | [] | Lib.IntTypes.gt_mask_lemma | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t Lib.IntTypes.SEC -> b: Lib.IntTypes.int_t t Lib.IntTypes.SEC
-> FStar.Pervasives.Lemma
(ensures
((match Lib.IntTypes.v a > Lib.IntTypes.v b with
| true -> Lib.IntTypes.v (Lib.IntTypes.gt_mask a b) == Lib.IntTypes.ones_v t
| _ -> Lib.IntTypes.v (Lib.IntTypes.gt_mask a b) == 0)
<:
Type0)) [SMTPat (Lib.IntTypes.gt_mask a b)] | {
"end_col": 28,
"end_line": 929,
"start_col": 2,
"start_line": 928
} |
FStar.Pervasives.Lemma | val logxor_spec: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma (v (a `logxor` b) == v a `logxor_v` v b) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> () | val logxor_spec: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma (v (a `logxor` b) == v a `logxor_v` v b)
let logxor_spec #t #l a b = | false | null | true | match t with
| U1 ->
assert_norm ((u1 0) `logxor` (u1 0) == u1 0 /\ (u1 0) `logxor` (u1 1) == u1 1);
assert_norm ((u1 1) `logxor` (u1 0) == u1 1 /\ (u1 1) `logxor` (u1 1) == u1 0);
assert_norm (logxor_v #U1 0 0 == 0 /\ logxor_v #U1 0 1 == 1);
assert_norm (logxor_v #U1 1 0 == 1 /\ logxor_v #U1 1 1 == 0)
| _ -> () | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.Pervasives.assert_norm",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.logxor_v",
"Lib.IntTypes.U1",
"Prims.unit",
"Lib.IntTypes.SEC",
"Lib.IntTypes.logxor",
"Lib.IntTypes.u1"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a) | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logxor_spec: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma (v (a `logxor` b) == v a `logxor_v` v b) | [] | Lib.IntTypes.logxor_spec | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma
(ensures
Lib.IntTypes.v (Lib.IntTypes.logxor a b) ==
Lib.IntTypes.logxor_v (Lib.IntTypes.v a) (Lib.IntTypes.v b)) | {
"end_col": 11,
"end_line": 487,
"start_col": 2,
"start_line": 481
} |
Prims.Tot | val div: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> int_t t PUB | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let div #t x y =
match t with
| U1 -> UInt8.div x y
| U8 -> UInt8.div x y
| U16 -> UInt16.div x y
| U32 -> UInt32.div x y
| U64 -> UInt64.div x y
| S8 -> Int.pow2_values 8; Int8.div x y
| S16 -> Int.pow2_values 16; Int16.div x y
| S32 -> Int.pow2_values 32; Int32.div x y
| S64 -> Int.pow2_values 64; Int64.div x y | val div: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> int_t t PUB
let div #t x y = | false | null | false | match t with
| U1 -> UInt8.div x y
| U8 -> UInt8.div x y
| U16 -> UInt16.div x y
| U32 -> UInt32.div x y
| U64 -> UInt64.div x y
| S8 ->
Int.pow2_values 8;
Int8.div x y
| S16 ->
Int.pow2_values 16;
Int16.div x y
| S32 ->
Int.pow2_values 32;
Int32.div x y
| S64 ->
Int.pow2_values 64;
Int64.div x y | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"total"
] | [
"Lib.IntTypes.inttype",
"Prims.l_and",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_U128",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"Prims.op_disEquality",
"Prims.int",
"Lib.IntTypes.v",
"Prims.l_or",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.range",
"FStar.Int.op_Slash",
"FStar.UInt8.div",
"FStar.UInt16.div",
"FStar.UInt32.div",
"FStar.UInt64.div",
"FStar.Int8.div",
"Prims.unit",
"FStar.Int.pow2_values",
"FStar.Int16.div",
"FStar.Int32.div",
"FStar.Int64.div"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t))
let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end
#pop-options
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000"
(**
Conditionally subtracts 2^(bits t') from a in constant-time,
so that the result fits in t'; i.e.
b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a
*)
inline_for_extraction
val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'}
let conditional_subtract #t #l t' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
// assert (v pow2_bits == pow2 (bits t'));
// assert (v pow2_bits_minus_one == pow2 (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
// assert (if v a2 < 0 then v mask = -1 else v mask = 0);
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits)
let cast_mod #t #l t' l' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
if bits t' >= bits t then
cast t' l' a
else
begin
let m = size (bits t') in
mod_mask_lemma a m;
let b = conditional_subtract t' (a `logand` mod_mask m) in
cast t' l' b
end
#pop-options
[@(strict_on_arguments [0])] | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val div: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> int_t t PUB | [] | Lib.IntTypes.div | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Lib.IntTypes.int_t t Lib.IntTypes.PUB ->
b:
Lib.IntTypes.int_t t Lib.IntTypes.PUB
{ Lib.IntTypes.v b <> 0 /\
(Lib.IntTypes.unsigned t \/ Lib.IntTypes.range (Lib.IntTypes.v a / Lib.IntTypes.v b) t) }
-> Lib.IntTypes.int_t t Lib.IntTypes.PUB | {
"end_col": 44,
"end_line": 1037,
"start_col": 2,
"start_line": 1028
} |
FStar.Pervasives.Lemma | val lte_mask_lemma: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a <= v b then v (lte_mask a b) == ones_v t
else v (lte_mask a b) == 0)
[SMTPat (lte_mask #t a b)] | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b)) | val lte_mask_lemma: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a <= v b then v (lte_mask a b) == ones_v t
else v (lte_mask a b) == 0)
[SMTPat (lte_mask #t a b)]
let lte_mask_lemma #t a b = | false | null | true | match t with
| U1 ->
assert_norm (logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8
| U16
| U32
| U64
| U128 ->
if v a > v b
then UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else
if v a = v b
then UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else UInt.logor_lemma_1 #(bits t) (v (lt_mask a b)) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"FStar.Pervasives.assert_norm",
"Prims.l_and",
"Prims.eq2",
"Lib.IntTypes.U1",
"Lib.IntTypes.logor",
"Lib.IntTypes.u1",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"FStar.UInt.logor_lemma_1",
"Lib.IntTypes.bits",
"Lib.IntTypes.lt_mask",
"Prims.bool",
"Prims.op_Equality",
"Lib.IntTypes.range_t",
"FStar.UInt.logor_lemma_2",
"Prims.unit"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b) | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lte_mask_lemma: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a <= v b then v (lte_mask a b) == ones_v t
else v (lte_mask a b) == 0)
[SMTPat (lte_mask #t a b)] | [] | Lib.IntTypes.lte_mask_lemma | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t Lib.IntTypes.SEC -> b: Lib.IntTypes.int_t t Lib.IntTypes.SEC
-> FStar.Pervasives.Lemma
(ensures
((match Lib.IntTypes.v a <= Lib.IntTypes.v b with
| true -> Lib.IntTypes.v (Lib.IntTypes.lte_mask a b) == Lib.IntTypes.ones_v t
| _ -> Lib.IntTypes.v (Lib.IntTypes.lte_mask a b) == 0)
<:
Type0)) [SMTPat (Lib.IntTypes.lte_mask a b)] | {
"end_col": 52,
"end_line": 945,
"start_col": 2,
"start_line": 934
} |
Prims.Tot | val lte: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lte #t x y =
match t with
| U1 -> UInt8.lte x y
| U8 -> UInt8.lte x y
| U16 -> UInt16.lte x y
| U32 -> UInt32.lte x y
| U64 -> UInt64.lte x y
| U128 -> UInt128.lte x y
| S8 -> Int8.lte x y
| S16 -> Int16.lte x y
| S32 -> Int32.lte x y
| S64 -> Int64.lte x y
| S128 -> Int128.lte x y | val lte: #t:inttype -> int_t t PUB -> int_t t PUB -> bool
let lte #t x y = | false | null | false | match t with
| U1 -> UInt8.lte x y
| U8 -> UInt8.lte x y
| U16 -> UInt16.lte x y
| U32 -> UInt32.lte x y
| U64 -> UInt64.lte x y
| U128 -> UInt128.lte x y
| S8 -> Int8.lte x y
| S16 -> Int16.lte x y
| S32 -> Int32.lte x y
| S64 -> Int64.lte x y
| S128 -> Int128.lte x y | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"total"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"FStar.UInt8.lte",
"FStar.UInt16.lte",
"FStar.UInt32.lte",
"FStar.UInt64.lte",
"FStar.UInt128.lte",
"FStar.Int8.lte",
"FStar.Int16.lte",
"FStar.Int32.lte",
"FStar.Int64.lte",
"FStar.Int128.lte",
"Prims.bool"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t))
let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end
#pop-options
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000"
(**
Conditionally subtracts 2^(bits t') from a in constant-time,
so that the result fits in t'; i.e.
b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a
*)
inline_for_extraction
val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'}
let conditional_subtract #t #l t' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
// assert (v pow2_bits == pow2 (bits t'));
// assert (v pow2_bits_minus_one == pow2 (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
// assert (if v a2 < 0 then v mask = -1 else v mask = 0);
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits)
let cast_mod #t #l t' l' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
if bits t' >= bits t then
cast t' l' a
else
begin
let m = size (bits t') in
mod_mask_lemma a m;
let b = conditional_subtract t' (a `logand` mod_mask m) in
cast t' l' b
end
#pop-options
[@(strict_on_arguments [0])]
let div #t x y =
match t with
| U1 -> UInt8.div x y
| U8 -> UInt8.div x y
| U16 -> UInt16.div x y
| U32 -> UInt32.div x y
| U64 -> UInt64.div x y
| S8 -> Int.pow2_values 8; Int8.div x y
| S16 -> Int.pow2_values 16; Int16.div x y
| S32 -> Int.pow2_values 32; Int32.div x y
| S64 -> Int.pow2_values 64; Int64.div x y
let div_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64
let mod #t x y =
match t with
| U1 -> UInt8.rem x y
| U8 -> UInt8.rem x y
| U16 -> UInt16.rem x y
| U32 -> UInt32.rem x y
| U64 -> UInt64.rem x y
| S8 -> Int.pow2_values 8; Int8.rem x y
| S16 -> Int.pow2_values 16; Int16.rem x y
| S32 -> Int.pow2_values 32; Int32.rem x y
| S64 -> Int.pow2_values 64; Int64.rem x y
let mod_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64
let eq #t x y =
x = y
let eq_lemma #t x y = ()
let ne #t x y = not (eq x y)
let ne_lemma #t x y = ()
let lt #t x y =
match t with
| U1 -> UInt8.lt x y
| U8 -> UInt8.lt x y
| U16 -> UInt16.lt x y
| U32 -> UInt32.lt x y
| U64 -> UInt64.lt x y
| U128 -> UInt128.lt x y
| S8 -> Int8.lt x y
| S16 -> Int16.lt x y
| S32 -> Int32.lt x y
| S64 -> Int64.lt x y
| S128 -> Int128.lt x y
let lt_lemma #t x y = () | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lte: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | [] | Lib.IntTypes.lte | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> y: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> Prims.bool | {
"end_col": 26,
"end_line": 1104,
"start_col": 2,
"start_line": 1093
} |
Prims.Tot | val lt: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lt #t x y =
match t with
| U1 -> UInt8.lt x y
| U8 -> UInt8.lt x y
| U16 -> UInt16.lt x y
| U32 -> UInt32.lt x y
| U64 -> UInt64.lt x y
| U128 -> UInt128.lt x y
| S8 -> Int8.lt x y
| S16 -> Int16.lt x y
| S32 -> Int32.lt x y
| S64 -> Int64.lt x y
| S128 -> Int128.lt x y | val lt: #t:inttype -> int_t t PUB -> int_t t PUB -> bool
let lt #t x y = | false | null | false | match t with
| U1 -> UInt8.lt x y
| U8 -> UInt8.lt x y
| U16 -> UInt16.lt x y
| U32 -> UInt32.lt x y
| U64 -> UInt64.lt x y
| U128 -> UInt128.lt x y
| S8 -> Int8.lt x y
| S16 -> Int16.lt x y
| S32 -> Int32.lt x y
| S64 -> Int64.lt x y
| S128 -> Int128.lt x y | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"total"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"FStar.UInt8.lt",
"FStar.UInt16.lt",
"FStar.UInt32.lt",
"FStar.UInt64.lt",
"FStar.UInt128.lt",
"FStar.Int8.lt",
"FStar.Int16.lt",
"FStar.Int32.lt",
"FStar.Int64.lt",
"FStar.Int128.lt",
"Prims.bool"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t))
let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end
#pop-options
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000"
(**
Conditionally subtracts 2^(bits t') from a in constant-time,
so that the result fits in t'; i.e.
b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a
*)
inline_for_extraction
val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'}
let conditional_subtract #t #l t' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
// assert (v pow2_bits == pow2 (bits t'));
// assert (v pow2_bits_minus_one == pow2 (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
// assert (if v a2 < 0 then v mask = -1 else v mask = 0);
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits)
let cast_mod #t #l t' l' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
if bits t' >= bits t then
cast t' l' a
else
begin
let m = size (bits t') in
mod_mask_lemma a m;
let b = conditional_subtract t' (a `logand` mod_mask m) in
cast t' l' b
end
#pop-options
[@(strict_on_arguments [0])]
let div #t x y =
match t with
| U1 -> UInt8.div x y
| U8 -> UInt8.div x y
| U16 -> UInt16.div x y
| U32 -> UInt32.div x y
| U64 -> UInt64.div x y
| S8 -> Int.pow2_values 8; Int8.div x y
| S16 -> Int.pow2_values 16; Int16.div x y
| S32 -> Int.pow2_values 32; Int32.div x y
| S64 -> Int.pow2_values 64; Int64.div x y
let div_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64
let mod #t x y =
match t with
| U1 -> UInt8.rem x y
| U8 -> UInt8.rem x y
| U16 -> UInt16.rem x y
| U32 -> UInt32.rem x y
| U64 -> UInt64.rem x y
| S8 -> Int.pow2_values 8; Int8.rem x y
| S16 -> Int.pow2_values 16; Int16.rem x y
| S32 -> Int.pow2_values 32; Int32.rem x y
| S64 -> Int.pow2_values 64; Int64.rem x y
let mod_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64
let eq #t x y =
x = y
let eq_lemma #t x y = ()
let ne #t x y = not (eq x y)
let ne_lemma #t x y = () | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lt: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | [] | Lib.IntTypes.lt | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> y: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> Prims.bool | {
"end_col": 25,
"end_line": 1088,
"start_col": 2,
"start_line": 1077
} |
Prims.Tot | val mod: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> int_t t PUB | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mod #t x y =
match t with
| U1 -> UInt8.rem x y
| U8 -> UInt8.rem x y
| U16 -> UInt16.rem x y
| U32 -> UInt32.rem x y
| U64 -> UInt64.rem x y
| S8 -> Int.pow2_values 8; Int8.rem x y
| S16 -> Int.pow2_values 16; Int16.rem x y
| S32 -> Int.pow2_values 32; Int32.rem x y
| S64 -> Int.pow2_values 64; Int64.rem x y | val mod: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> int_t t PUB
let mod #t x y = | false | null | false | match t with
| U1 -> UInt8.rem x y
| U8 -> UInt8.rem x y
| U16 -> UInt16.rem x y
| U32 -> UInt32.rem x y
| U64 -> UInt64.rem x y
| S8 ->
Int.pow2_values 8;
Int8.rem x y
| S16 ->
Int.pow2_values 16;
Int16.rem x y
| S32 ->
Int.pow2_values 32;
Int32.rem x y
| S64 ->
Int.pow2_values 64;
Int64.rem x y | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"total"
] | [
"Lib.IntTypes.inttype",
"Prims.l_and",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_U128",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"Prims.op_disEquality",
"Prims.int",
"Lib.IntTypes.v",
"Prims.l_or",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.range",
"FStar.Int.op_Slash",
"FStar.UInt8.rem",
"FStar.UInt16.rem",
"FStar.UInt32.rem",
"FStar.UInt64.rem",
"FStar.Int8.rem",
"Prims.unit",
"FStar.Int.pow2_values",
"FStar.Int16.rem",
"FStar.Int32.rem",
"FStar.Int64.rem"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t))
let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end
#pop-options
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000"
(**
Conditionally subtracts 2^(bits t') from a in constant-time,
so that the result fits in t'; i.e.
b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a
*)
inline_for_extraction
val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'}
let conditional_subtract #t #l t' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
// assert (v pow2_bits == pow2 (bits t'));
// assert (v pow2_bits_minus_one == pow2 (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
// assert (if v a2 < 0 then v mask = -1 else v mask = 0);
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits)
let cast_mod #t #l t' l' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
if bits t' >= bits t then
cast t' l' a
else
begin
let m = size (bits t') in
mod_mask_lemma a m;
let b = conditional_subtract t' (a `logand` mod_mask m) in
cast t' l' b
end
#pop-options
[@(strict_on_arguments [0])]
let div #t x y =
match t with
| U1 -> UInt8.div x y
| U8 -> UInt8.div x y
| U16 -> UInt16.div x y
| U32 -> UInt32.div x y
| U64 -> UInt64.div x y
| S8 -> Int.pow2_values 8; Int8.div x y
| S16 -> Int.pow2_values 16; Int16.div x y
| S32 -> Int.pow2_values 32; Int32.div x y
| S64 -> Int.pow2_values 64; Int64.div x y
let div_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64 | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mod: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> int_t t PUB | [] | Lib.IntTypes.mod | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Lib.IntTypes.int_t t Lib.IntTypes.PUB ->
b:
Lib.IntTypes.int_t t Lib.IntTypes.PUB
{ Lib.IntTypes.v b <> 0 /\
(Lib.IntTypes.unsigned t \/ Lib.IntTypes.range (Lib.IntTypes.v a / Lib.IntTypes.v b) t) }
-> Lib.IntTypes.int_t t Lib.IntTypes.PUB | {
"end_col": 44,
"end_line": 1057,
"start_col": 2,
"start_line": 1048
} |
FStar.Pervasives.Lemma | val div_lemma: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> Lemma (v (div a b) == FStar.Int.(v a / v b))
[SMTPat (v #t (div #t a b))] | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let div_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64 | val div_lemma: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> Lemma (v (div a b) == FStar.Int.(v a / v b))
[SMTPat (v #t (div #t a b))]
let div_lemma #t a b = | false | null | true | match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64 | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Prims.l_and",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_U128",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"Prims.op_disEquality",
"Prims.int",
"Lib.IntTypes.v",
"Prims.l_or",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.range",
"FStar.Int.op_Slash",
"FStar.Int.pow2_values",
"Prims.unit"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t))
let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end
#pop-options
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000"
(**
Conditionally subtracts 2^(bits t') from a in constant-time,
so that the result fits in t'; i.e.
b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a
*)
inline_for_extraction
val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'}
let conditional_subtract #t #l t' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
// assert (v pow2_bits == pow2 (bits t'));
// assert (v pow2_bits_minus_one == pow2 (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
// assert (if v a2 < 0 then v mask = -1 else v mask = 0);
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits)
let cast_mod #t #l t' l' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
if bits t' >= bits t then
cast t' l' a
else
begin
let m = size (bits t') in
mod_mask_lemma a m;
let b = conditional_subtract t' (a `logand` mod_mask m) in
cast t' l' b
end
#pop-options
[@(strict_on_arguments [0])]
let div #t x y =
match t with
| U1 -> UInt8.div x y
| U8 -> UInt8.div x y
| U16 -> UInt16.div x y
| U32 -> UInt32.div x y
| U64 -> UInt64.div x y
| S8 -> Int.pow2_values 8; Int8.div x y
| S16 -> Int.pow2_values 16; Int16.div x y
| S32 -> Int.pow2_values 32; Int32.div x y
| S64 -> Int.pow2_values 64; Int64.div x y | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val div_lemma: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> Lemma (v (div a b) == FStar.Int.(v a / v b))
[SMTPat (v #t (div #t a b))] | [] | Lib.IntTypes.div_lemma | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Lib.IntTypes.int_t t Lib.IntTypes.PUB ->
b:
Lib.IntTypes.int_t t Lib.IntTypes.PUB
{ Lib.IntTypes.v b <> 0 /\
(Lib.IntTypes.unsigned t \/ Lib.IntTypes.range (Lib.IntTypes.v a / Lib.IntTypes.v b) t) }
-> FStar.Pervasives.Lemma
(ensures Lib.IntTypes.v (Lib.IntTypes.div a b) == Lib.IntTypes.v a / Lib.IntTypes.v b)
[SMTPat (Lib.IntTypes.v (Lib.IntTypes.div a b))] | {
"end_col": 29,
"end_line": 1045,
"start_col": 2,
"start_line": 1040
} |
FStar.Pervasives.Lemma | val mod_mask_lemma: #t:inttype -> #l:secrecy_level
-> a:int_t t l -> m:shiftval t{pow2 (uint_v m) <= maxint t}
-> Lemma (v (a `logand` mod_mask m) == v a % pow2 (v m))
[SMTPat (a `logand` mod_mask #t m)] | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end | val mod_mask_lemma: #t:inttype -> #l:secrecy_level
-> a:int_t t l -> m:shiftval t{pow2 (uint_v m) <= maxint t}
-> Lemma (v (a `logand` mod_mask m) == v a % pow2 (v m))
[SMTPat (a `logand` mod_mask #t m)]
let mod_mask_lemma #t #l a m = | false | null | true | mod_mask_value #t #l m;
if unsigned t || 0 <= v a
then if v m = 0 then UInt.logand_lemma_1 #(bits t) (v a) else UInt.logand_mask #(bits t) (v a) (v m)
else
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then UInt.logand_lemma_1 #(bits t) a2 else UInt.logand_mask #(bits t) a2 (v m) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Lib.IntTypes.shiftval",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.pow2",
"Lib.IntTypes.uint_v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.maxint",
"Prims.op_BarBar",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.v",
"Prims.op_Equality",
"Prims.int",
"FStar.UInt.logand_lemma_1",
"Lib.IntTypes.bits",
"Prims.bool",
"FStar.UInt.logand_mask",
"Prims.unit",
"FStar.Math.Lemmas.lemma_mod_plus",
"Prims.op_Subtraction",
"FStar.Math.Lemmas.pow2_le_compat",
"FStar.Math.Lemmas.pow2_plus",
"Prims.op_Addition",
"Lib.IntTypes.range",
"Lib.IntTypes.mod_mask_value"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t)) | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mod_mask_lemma: #t:inttype -> #l:secrecy_level
-> a:int_t t l -> m:shiftval t{pow2 (uint_v m) <= maxint t}
-> Lemma (v (a `logand` mod_mask m) == v a % pow2 (v m))
[SMTPat (a `logand` mod_mask #t m)] | [] | Lib.IntTypes.mod_mask_lemma | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Lib.IntTypes.int_t t l ->
m: Lib.IntTypes.shiftval t {Prims.pow2 (Lib.IntTypes.uint_v m) <= Lib.IntTypes.maxint t}
-> FStar.Pervasives.Lemma
(ensures
Lib.IntTypes.v (Lib.IntTypes.logand a (Lib.IntTypes.mod_mask m)) ==
Lib.IntTypes.v a % Prims.pow2 (Lib.IntTypes.v m))
[SMTPat (Lib.IntTypes.logand a (Lib.IntTypes.mod_mask m))] | {
"end_col": 7,
"end_line": 976,
"start_col": 2,
"start_line": 959
} |
FStar.Pervasives.Lemma | val mod_lemma: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> Lemma (if signed t then
v (mod a b) == FStar.Int.mod #(bits t) (v a) (v b)
else
v (mod a b) == FStar.UInt.mod #(bits t) (v a) (v b))
[SMTPat (v #t (mod #t a b))] | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mod_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64 | val mod_lemma: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> Lemma (if signed t then
v (mod a b) == FStar.Int.mod #(bits t) (v a) (v b)
else
v (mod a b) == FStar.UInt.mod #(bits t) (v a) (v b))
[SMTPat (v #t (mod #t a b))]
let mod_lemma #t a b = | false | null | true | match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64 | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Prims.l_and",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_U128",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"Prims.op_disEquality",
"Prims.int",
"Lib.IntTypes.v",
"Prims.l_or",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.range",
"FStar.Int.op_Slash",
"FStar.Int.pow2_values",
"Prims.unit"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t))
let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end
#pop-options
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000"
(**
Conditionally subtracts 2^(bits t') from a in constant-time,
so that the result fits in t'; i.e.
b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a
*)
inline_for_extraction
val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'}
let conditional_subtract #t #l t' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
// assert (v pow2_bits == pow2 (bits t'));
// assert (v pow2_bits_minus_one == pow2 (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
// assert (if v a2 < 0 then v mask = -1 else v mask = 0);
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits)
let cast_mod #t #l t' l' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
if bits t' >= bits t then
cast t' l' a
else
begin
let m = size (bits t') in
mod_mask_lemma a m;
let b = conditional_subtract t' (a `logand` mod_mask m) in
cast t' l' b
end
#pop-options
[@(strict_on_arguments [0])]
let div #t x y =
match t with
| U1 -> UInt8.div x y
| U8 -> UInt8.div x y
| U16 -> UInt16.div x y
| U32 -> UInt32.div x y
| U64 -> UInt64.div x y
| S8 -> Int.pow2_values 8; Int8.div x y
| S16 -> Int.pow2_values 16; Int16.div x y
| S32 -> Int.pow2_values 32; Int32.div x y
| S64 -> Int.pow2_values 64; Int64.div x y
let div_lemma #t a b =
match t with
| U1 | U8 | U16 | U32 | U64 -> ()
| S8 -> Int.pow2_values 8
| S16 -> Int.pow2_values 16
| S32 -> Int.pow2_values 32
| S64 -> Int.pow2_values 64
let mod #t x y =
match t with
| U1 -> UInt8.rem x y
| U8 -> UInt8.rem x y
| U16 -> UInt16.rem x y
| U32 -> UInt32.rem x y
| U64 -> UInt64.rem x y
| S8 -> Int.pow2_values 8; Int8.rem x y
| S16 -> Int.pow2_values 16; Int16.rem x y
| S32 -> Int.pow2_values 32; Int32.rem x y
| S64 -> Int.pow2_values 64; Int64.rem x y | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mod_lemma: #t:inttype{~(U128? t) /\ ~(S128? t)}
-> a:int_t t PUB
-> b:int_t t PUB{v b <> 0 /\ (unsigned t \/ range FStar.Int.(v a / v b) t)}
-> Lemma (if signed t then
v (mod a b) == FStar.Int.mod #(bits t) (v a) (v b)
else
v (mod a b) == FStar.UInt.mod #(bits t) (v a) (v b))
[SMTPat (v #t (mod #t a b))] | [] | Lib.IntTypes.mod_lemma | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Lib.IntTypes.int_t t Lib.IntTypes.PUB ->
b:
Lib.IntTypes.int_t t Lib.IntTypes.PUB
{ Lib.IntTypes.v b <> 0 /\
(Lib.IntTypes.unsigned t \/ Lib.IntTypes.range (Lib.IntTypes.v a / Lib.IntTypes.v b) t) }
-> FStar.Pervasives.Lemma
(ensures
((match Lib.IntTypes.signed t with
| true ->
Lib.IntTypes.v (Lib.IntTypes.mod a b) ==
FStar.Int.mod (Lib.IntTypes.v a) (Lib.IntTypes.v b)
| _ ->
Lib.IntTypes.v (Lib.IntTypes.mod a b) ==
FStar.UInt.mod (Lib.IntTypes.v a) (Lib.IntTypes.v b))
<:
Type0)) [SMTPat (Lib.IntTypes.v (Lib.IntTypes.mod a b))] | {
"end_col": 29,
"end_line": 1065,
"start_col": 2,
"start_line": 1060
} |
FStar.Pervasives.Lemma | val neq_mask_lemma: #t:inttype{~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (neq_mask a b) == 0
else v (neq_mask a b) == ones_v t)
[SMTPat (neq_mask #t a b)] | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0 | val neq_mask_lemma: #t:inttype{~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (neq_mask a b) == 0
else v (neq_mask a b) == ones_v t)
[SMTPat (neq_mask #t a b)]
let neq_mask_lemma #t a b = | false | null | true | match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0 | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"FStar.Pervasives.assert_norm",
"Prims.l_and",
"Prims.eq2",
"Lib.IntTypes.U1",
"Lib.IntTypes.lognot",
"Lib.IntTypes.u1",
"FStar.UInt.lognot_self",
"Lib.IntTypes.bits",
"Prims.unit",
"FStar.UInt.lognot_lemma_1"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b) | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val neq_mask_lemma: #t:inttype{~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (neq_mask a b) == 0
else v (neq_mask a b) == ones_v t)
[SMTPat (neq_mask #t a b)] | [] | Lib.IntTypes.neq_mask_lemma | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t Lib.IntTypes.SEC -> b: Lib.IntTypes.int_t t Lib.IntTypes.SEC
-> FStar.Pervasives.Lemma
(ensures
((match Lib.IntTypes.v a = Lib.IntTypes.v b with
| true -> Lib.IntTypes.v (Lib.IntTypes.neq_mask a b) == 0
| _ -> Lib.IntTypes.v (Lib.IntTypes.neq_mask a b) == Lib.IntTypes.ones_v t)
<:
Type0)) [SMTPat (Lib.IntTypes.neq_mask a b)] | {
"end_col": 32,
"end_line": 884,
"start_col": 2,
"start_line": 880
} |
Prims.Tot | val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let conditional_subtract #t #l t' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
// assert (v pow2_bits == pow2 (bits t'));
// assert (v pow2_bits_minus_one == pow2 (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
// assert (if v a2 < 0 then v mask = -1 else v mask = 0);
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits) | val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'}
let conditional_subtract #t #l t' a = | false | null | false | assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"total"
] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.signed",
"Lib.IntTypes.secrecy_level",
"Prims.l_and",
"Prims.op_LessThan",
"Lib.IntTypes.bits",
"Lib.IntTypes.int_t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Prims.op_Subtraction",
"Prims.pow2",
"Lib.IntTypes.add",
"Lib.IntTypes.logand",
"Prims.unit",
"Lib.IntTypes.logand_lemma",
"Lib.IntTypes.sub",
"Lib.IntTypes.shift_right_lemma",
"Lib.IntTypes.size",
"Lib.IntTypes.shift_right",
"Lib.IntTypes.shift_left_lemma",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.shift_left",
"FStar.Pervasives.assert_norm",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.op_At_Percent_Dot"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t))
let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end
#pop-options
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000"
(**
Conditionally subtracts 2^(bits t') from a in constant-time,
so that the result fits in t'; i.e.
b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a
*)
inline_for_extraction
val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'} | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 1000,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'} | [] | Lib.IntTypes.conditional_subtract | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
t': Lib.IntTypes.inttype{Lib.IntTypes.signed t' /\ Lib.IntTypes.bits t' < Lib.IntTypes.bits t} ->
a:
Lib.IntTypes.int_t t l
{0 <= Lib.IntTypes.v a /\ Lib.IntTypes.v a <= Prims.pow2 (Lib.IntTypes.bits t') - 1}
-> b: Lib.IntTypes.int_t t l {Lib.IntTypes.v b = Lib.IntTypes.v a @%. t'} | {
"end_col": 36,
"end_line": 1009,
"start_col": 2,
"start_line": 995
} |
FStar.Pervasives.Lemma | val logxor_lemma: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(a `logxor` (a `logxor` b) == b /\
a `logxor` (b `logxor` a) == b /\
a `logxor` (mk_int #t #l 0) == a) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a | val logxor_lemma: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(a `logxor` (a `logxor` b) == b /\
a `logxor` (b `logxor` a) == b /\
a `logxor` (mk_int #t #l 0) == a)
let logxor_lemma #t #l a b = | false | null | true | logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
(match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b));
v_extensionality (logxor a (logxor b a)) b;
(match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a));
v_extensionality (logxor a (mk_int #t #l 0)) a | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Lib.IntTypes.v_extensionality",
"Lib.IntTypes.logxor",
"Lib.IntTypes.mk_int",
"Prims.unit",
"FStar.UInt.logxor_lemma_1",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"FStar.Int.logxor_lemma_1",
"FStar.UInt.logxor_commutative",
"FStar.Int.logxor_commutative",
"Lib.IntTypes.logxor_lemma_"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b) | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logxor_lemma: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(a `logxor` (a `logxor` b) == b /\
a `logxor` (b `logxor` a) == b /\
a `logxor` (mk_int #t #l 0) == a) | [] | Lib.IntTypes.logxor_lemma | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma
(ensures
Lib.IntTypes.logxor a (Lib.IntTypes.logxor a b) == b /\
Lib.IntTypes.logxor a (Lib.IntTypes.logxor b a) == b /\
Lib.IntTypes.logxor a (Lib.IntTypes.mk_int 0) == a) | {
"end_col": 48,
"end_line": 467,
"start_col": 2,
"start_line": 454
} |
FStar.Pervasives.Lemma | val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t)) | val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m = | false | null | true | shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t)) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.shiftval",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.pow2",
"Lib.IntTypes.uint_v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.maxint",
"FStar.Math.Lemmas.small_modulo_lemma_1",
"Prims.op_Subtraction",
"Lib.IntTypes.v",
"Lib.IntTypes.bits",
"Prims.unit",
"FStar.Math.Lemmas.pow2_lt_compat",
"FStar.Math.Lemmas.pow2_double_mult",
"Lib.IntTypes.shift_left_lemma",
"Lib.IntTypes.mk_int"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1) | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1) | [] | Lib.IntTypes.mod_mask_value | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | m: Lib.IntTypes.shiftval t {Prims.pow2 (Lib.IntTypes.uint_v m) <= Lib.IntTypes.maxint t}
-> FStar.Pervasives.Lemma
(ensures Lib.IntTypes.v (Lib.IntTypes.mod_mask m) == Prims.pow2 (Lib.IntTypes.v m) - 1) | {
"end_col": 55,
"end_line": 956,
"start_col": 2,
"start_line": 952
} |
Prims.Tot | val cast_mod: #t:inttype{signed t} -> #l:secrecy_level
-> t':inttype{signed t'}
-> l':secrecy_level{PUB? l \/ SEC? l'}
-> a:int_t t l
-> b:int_t t' l'{v b == v a @%. t'} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cast_mod #t #l t' l' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
if bits t' >= bits t then
cast t' l' a
else
begin
let m = size (bits t') in
mod_mask_lemma a m;
let b = conditional_subtract t' (a `logand` mod_mask m) in
cast t' l' b
end | val cast_mod: #t:inttype{signed t} -> #l:secrecy_level
-> t':inttype{signed t'}
-> l':secrecy_level{PUB? l \/ SEC? l'}
-> a:int_t t l
-> b:int_t t' l'{v b == v a @%. t'}
let cast_mod #t #l t' l' a = | false | null | false | assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
if bits t' >= bits t
then cast t' l' a
else
let m = size (bits t') in
mod_mask_lemma a m;
let b = conditional_subtract t' (a `logand` (mod_mask m)) in
cast t' l' b | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"total"
] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.signed",
"Lib.IntTypes.secrecy_level",
"Prims.l_or",
"Lib.IntTypes.uu___is_PUB",
"Lib.IntTypes.uu___is_SEC",
"Lib.IntTypes.int_t",
"Prims.op_GreaterThanOrEqual",
"Lib.IntTypes.bits",
"Lib.IntTypes.cast",
"Prims.bool",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.v",
"Lib.IntTypes.op_At_Percent_Dot",
"Lib.IntTypes.logand",
"Lib.IntTypes.mod_mask",
"Lib.IntTypes.conditional_subtract",
"Prims.unit",
"Lib.IntTypes.mod_mask_lemma",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.size",
"Prims.eq2",
"FStar.Pervasives.assert_norm",
"Prims.pow2"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end
#pop-options
let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b
let eq_mask_logand_lemma #t a b c =
eq_mask_lemma a b;
logand_zeros c;
logand_ones c;
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
| S8 | S16 | S32 | S64 -> Int.logand_commutative #(bits t) (v (eq_mask a b)) (v c)
[@(strict_on_arguments [0])]
let neq_mask #t a b = lognot (eq_mask #t a b)
let neq_mask_lemma #t a b =
match t with
| U1 -> assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ ->
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
[@(strict_on_arguments [0])]
let gte_mask #t a b =
match t with
| U1 -> logor a (lognot b)
| U8 -> UInt8.gte_mask a b
| U16 -> UInt16.gte_mask a b
| U32 -> UInt32.gte_mask a b
| U64 -> UInt64.gte_mask a b
| U128 -> UInt128.gte_mask a b
let gte_mask_lemma #t a b =
match t with
| U1 ->
begin
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
end
| _ -> ()
let gte_mask_logand_lemma #t a b c =
logand_zeros c;
logand_ones c;
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| _ -> UInt.logand_commutative #(bits t) (v (gte_mask a b)) (v c)
let lt_mask #t a b = lognot (gte_mask a b)
let lt_mask_lemma #t a b =
assert_norm (lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1);
UInt.lognot_lemma_1 #(bits t);
UInt.lognot_self #(bits t) 0
let gt_mask #t a b = logand (gte_mask a b) (neq_mask a b)
let gt_mask_lemma #t a b =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b)
let lte_mask #t a b = logor (lt_mask a b) (eq_mask a b)
let lte_mask_lemma #t a b =
match t with
| U1 ->
assert_norm (
logor (u1 0) (u1 0) == u1 0 /\ logor (u1 1) (u1 1) == u1 1 /\
logor (u1 0) (u1 1) == u1 1 /\ logor (u1 1) (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 ->
if v a > v b then
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
else if v a = v b then
UInt.logor_lemma_2 #(bits t) (v (lt_mask a b))
else
UInt.logor_lemma_1 #(bits t) (v (lt_mask a b))
#push-options "--max_fuel 1"
val mod_mask_value: #t:inttype -> #l:secrecy_level -> m:shiftval t{pow2 (uint_v m) <= maxint t} ->
Lemma (v (mod_mask #t #l m) == pow2 (v m) - 1)
let mod_mask_value #t #l m =
shift_left_lemma (mk_int #t #l 1) m;
pow2_double_mult (bits t - 1);
pow2_lt_compat (bits t) (v m);
small_modulo_lemma_1 (pow2 (v m)) (pow2 (bits t));
small_modulo_lemma_1 (pow2 (v m) - 1) (pow2 (bits t))
let mod_mask_lemma #t #l a m =
mod_mask_value #t #l m;
if unsigned t || 0 <= v a then
if v m = 0 then
UInt.logand_lemma_1 #(bits t) (v a)
else
UInt.logand_mask #(bits t) (v a) (v m)
else
begin
let a1 = v a in
let a2 = v a + pow2 (bits t) in
pow2_plus (bits t - v m) (v m);
pow2_le_compat (bits t - 1) (v m);
lemma_mod_plus a1 (pow2 (bits t - v m)) (pow2 (v m));
if v m = 0 then
UInt.logand_lemma_1 #(bits t) a2
else
UInt.logand_mask #(bits t) a2 (v m)
end
#pop-options
#push-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 1000"
(**
Conditionally subtracts 2^(bits t') from a in constant-time,
so that the result fits in t'; i.e.
b = if a >= 2^(bits t' - 1) then a - 2^(bits t') else a
*)
inline_for_extraction
val conditional_subtract:
#t:inttype{signed t}
-> #l:secrecy_level
-> t':inttype{signed t' /\ bits t' < bits t}
-> a:int_t t l{0 <= v a /\ v a <= pow2 (bits t') - 1}
-> b:int_t t l{v b = v a @%. t'}
let conditional_subtract #t #l t' a =
assert_norm (pow2 7 = 128);
assert_norm (pow2 15 = 32768);
let pow2_bits = shift_left #t #l (mk_int 1) (size (bits t')) in
shift_left_lemma #t #l (mk_int 1) (size (bits t'));
let pow2_bits_minus_one = shift_left #t #l (mk_int 1) (size (bits t' - 1)) in
shift_left_lemma #t #l (mk_int 1) (size (bits t' - 1));
// assert (v pow2_bits == pow2 (bits t'));
// assert (v pow2_bits_minus_one == pow2 (bits t' - 1));
let a2 = a `sub` pow2_bits_minus_one in
let mask = shift_right a2 (size (bits t - 1)) in
shift_right_lemma a2 (size (bits t - 1));
// assert (if v a2 < 0 then v mask = -1 else v mask = 0);
let a3 = a `sub` pow2_bits in
logand_lemma mask pow2_bits;
a3 `add` (mask `logand` pow2_bits) | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 1000,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cast_mod: #t:inttype{signed t} -> #l:secrecy_level
-> t':inttype{signed t'}
-> l':secrecy_level{PUB? l \/ SEC? l'}
-> a:int_t t l
-> b:int_t t' l'{v b == v a @%. t'} | [] | Lib.IntTypes.cast_mod | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
t': Lib.IntTypes.inttype{Lib.IntTypes.signed t'} ->
l': Lib.IntTypes.secrecy_level{PUB? l \/ SEC? l'} ->
a: Lib.IntTypes.int_t t l
-> b: Lib.IntTypes.int_t t' l' {Lib.IntTypes.v b == Lib.IntTypes.v a @%. t'} | {
"end_col": 7,
"end_line": 1022,
"start_col": 2,
"start_line": 1012
} |
FStar.Pervasives.Lemma | val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let eq_mask_lemma_signed #t a b =
match t with
| S8 ->
begin
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a then modulo_lemma (v a) (pow2 8)
else
begin
modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8)
end
end
| S16 ->
begin
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a then modulo_lemma (v a) (pow2 16)
else
begin
modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16)
end
end
| S32 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 32)
else
begin
modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32)
end
end
| S64 ->
begin
if 0 <= v a then modulo_lemma (v a) (pow2 64)
else
begin
modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)
end
end | val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_signed #t a b = | false | null | true | match t with
| S8 ->
assert_norm (pow2 8 = 2 * pow2 7);
if 0 <= v a
then modulo_lemma (v a) (pow2 8)
else
(modulo_addition_lemma (v a) 1 (pow2 8);
modulo_lemma (v a + pow2 8) (pow2 8))
| S16 ->
assert_norm (pow2 16 = 2 * pow2 15);
if 0 <= v a
then modulo_lemma (v a) (pow2 16)
else
(modulo_addition_lemma (v a) 1 (pow2 16);
modulo_lemma (v a + pow2 16) (pow2 16))
| S32 ->
if 0 <= v a
then modulo_lemma (v a) (pow2 32)
else
(modulo_addition_lemma (v a) 1 (pow2 32);
modulo_lemma (v a + pow2 32) (pow2 32))
| S64 ->
if 0 <= v a
then modulo_lemma (v a) (pow2 64)
else
(modulo_addition_lemma (v a) 1 (pow2 64);
modulo_lemma (v a + pow2 64) (pow2 64)) | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"lemma"
] | [
"Lib.IntTypes.inttype",
"Prims.l_and",
"Prims.b2t",
"Lib.IntTypes.signed",
"Prims.l_not",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"FStar.Math.Lemmas.modulo_lemma",
"Prims.pow2",
"Prims.bool",
"Prims.op_Addition",
"Prims.unit",
"FStar.Math.Lemmas.modulo_addition_lemma",
"FStar.Pervasives.assert_norm",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])]
let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u
#pop-options
[@(strict_on_arguments [0])]
let ones t l =
match t with
| U1 -> 0x1uy
| U8 -> 0xFFuy
| U16 -> 0xFFFFus
| U32 -> 0xFFFFFFFFul
| U64 -> 0xFFFFFFFFFFFFFFFFuL
| U128 ->
let x = UInt128.uint64_to_uint128 0xFFFFFFFFFFFFFFFFuL in
let y = (UInt128.shift_left x 64ul) `UInt128.add` x in
assert_norm (UInt128.v y == pow2 128 - 1);
y
| _ -> mk_int (-1)
let zeros t l = mk_int 0
[@(strict_on_arguments [0])]
let add_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.add_mod a b) 2uy
| U8 -> UInt8.add_mod a b
| U16 -> UInt16.add_mod a b
| U32 -> UInt32.add_mod a b
| U64 -> UInt64.add_mod a b
| U128 -> UInt128.add_mod a b
let add_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let add #t #l a b =
match t with
| U1 -> UInt8.add a b
| U8 -> UInt8.add a b
| U16 -> UInt16.add a b
| U32 -> UInt32.add a b
| U64 -> UInt64.add a b
| U128 -> UInt128.add a b
| S8 -> Int8.add a b
| S16 -> Int16.add a b
| S32 -> Int32.add a b
| S64 -> Int64.add a b
| S128 -> Int128.add a b
let add_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let incr #t #l a =
match t with
| U1 -> UInt8.add a 1uy
| U8 -> UInt8.add a 1uy
| U16 -> UInt16.add a 1us
| U32 -> UInt32.add a 1ul
| U64 -> UInt64.add a 1uL
| U128 -> UInt128.add a (UInt128.uint_to_t 1)
| S8 -> Int8.add a 1y
| S16 -> Int16.add a 1s
| S32 -> Int32.add a 1l
| S64 -> Int64.add a 1L
| S128 -> Int128.add a (Int128.int_to_t 1)
let incr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let mul_mod #t #l a b =
match t with
| U1 -> UInt8.mul_mod a b
| U8 -> UInt8.mul_mod a b
| U16 -> UInt16.mul_mod a b
| U32 -> UInt32.mul_mod a b
| U64 -> UInt64.mul_mod a b
let mul_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let mul #t #l a b =
match t with
| U1 -> UInt8.mul a b
| U8 -> UInt8.mul a b
| U16 -> UInt16.mul a b
| U32 -> UInt32.mul a b
| U64 -> UInt64.mul a b
| S8 -> Int8.mul a b
| S16 -> Int16.mul a b
| S32 -> Int32.mul a b
| S64 -> Int64.mul a b
let mul_lemma #t #l a b = ()
let mul64_wide a b = UInt128.mul_wide a b
let mul64_wide_lemma a b = ()
let mul_s64_wide a b = Int128.mul_wide a b
let mul_s64_wide_lemma a b = ()
[@(strict_on_arguments [0])]
let sub_mod #t #l a b =
match t with
| U1 -> UInt8.rem (UInt8.sub_mod a b) 2uy
| U8 -> UInt8.sub_mod a b
| U16 -> UInt16.sub_mod a b
| U32 -> UInt32.sub_mod a b
| U64 -> UInt64.sub_mod a b
| U128 -> UInt128.sub_mod a b
let sub_mod_lemma #t #l a b = ()
[@(strict_on_arguments [0])]
let sub #t #l a b =
match t with
| U1 -> UInt8.sub a b
| U8 -> UInt8.sub a b
| U16 -> UInt16.sub a b
| U32 -> UInt32.sub a b
| U64 -> UInt64.sub a b
| U128 -> UInt128.sub a b
| S8 -> Int8.sub a b
| S16 -> Int16.sub a b
| S32 -> Int32.sub a b
| S64 -> Int64.sub a b
| S128 -> Int128.sub a b
let sub_lemma #t #l a b = ()
#push-options "--max_fuel 1"
[@(strict_on_arguments [0])]
let decr #t #l a =
match t with
| U1 -> UInt8.sub a 1uy
| U8 -> UInt8.sub a 1uy
| U16 -> UInt16.sub a 1us
| U32 -> UInt32.sub a 1ul
| U64 -> UInt64.sub a 1uL
| U128 -> UInt128.sub a (UInt128.uint_to_t 1)
| S8 -> Int8.sub a 1y
| S16 -> Int16.sub a 1s
| S32 -> Int32.sub a 1l
| S64 -> Int64.sub a 1L
| S128 -> Int128.sub a (Int128.int_to_t 1)
let decr_lemma #t #l a = ()
#pop-options
[@(strict_on_arguments [0])]
let logxor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logxor 0uy 0uy == 0uy);
assert_norm (UInt8.logxor 0uy 1uy == 1uy);
assert_norm (UInt8.logxor 1uy 0uy == 1uy);
assert_norm (UInt8.logxor 1uy 1uy == 0uy);
UInt8.logxor a b
| U8 -> UInt8.logxor a b
| U16 -> UInt16.logxor a b
| U32 -> UInt32.logxor a b
| U64 -> UInt64.logxor a b
| U128 -> UInt128.logxor a b
| S8 -> Int8.logxor a b
| S16 -> Int16.logxor a b
| S32 -> Int32.logxor a b
| S64 -> Int64.logxor a b
| S128 -> Int128.logxor a b
#push-options "--max_fuel 1"
val logxor_lemma_: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(v (a `logxor` (a `logxor` b)) == v b)
let logxor_lemma_ #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 ->
UInt.logxor_associative #(bits t) (v a) (v a) (v b);
UInt.logxor_self #(bits t) (v a);
UInt.logxor_commutative #(bits t) 0 (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| S8 | S16 | S32 | S64 | S128 ->
Int.logxor_associative #(bits t) (v a) (v a) (v b);
Int.logxor_self #(bits t) (v a);
Int.logxor_commutative #(bits t) 0 (v b);
Int.logxor_lemma_1 #(bits t) (v b)
let logxor_lemma #t #l a b =
logxor_lemma_ #t a b;
v_extensionality (logxor a (logxor a b)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_commutative #(bits t) (v a) (v b)
end;
v_extensionality (logxor a (logxor b a)) b;
begin
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> UInt.logxor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logxor_lemma_1 #(bits t) (v a)
end;
v_extensionality (logxor a (mk_int #t #l 0)) a
let logxor_lemma1 #t #l a b =
match v a, v b with
| _, 0 ->
UInt.logxor_lemma_1 #(bits t) (v a)
| 0, _ ->
UInt.logxor_commutative #(bits t) (v a) (v b);
UInt.logxor_lemma_1 #(bits t) (v b)
| 1, 1 ->
v_extensionality a b;
UInt.logxor_self #(bits t) (v a)
let logxor_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logxor` u1 0 == u1 0 /\ u1 0 `logxor` u1 1 == u1 1);
assert_norm (u1 1 `logxor` u1 0 == u1 1 /\ u1 1 `logxor` u1 1 == u1 0);
assert_norm (0 `logxor_v #U1` 0 == 0 /\ 0 `logxor_v #U1` 1 == 1);
assert_norm (1 `logxor_v #U1` 0 == 1 /\ 1 `logxor_v #U1` 1 == 0)
| _ -> ()
#pop-options
[@(strict_on_arguments [0])]
let logand #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy);
UInt8.logand a b
| U8 -> UInt8.logand a b
| U16 -> UInt16.logand a b
| U32 -> UInt32.logand a b
| U64 -> UInt64.logand a b
| U128 -> UInt128.logand a b
| S8 -> Int8.logand a b
| S16 -> Int16.logand a b
| S32 -> Int32.logand a b
| S64 -> Int64.logand a b
| S128 -> Int128.logand a b
let logand_zeros #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_1 #(bits t) (v a)
let logand_ones #t #l a =
match t with
| U1 -> assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_lemma_2 #(bits t) (v a)
let logand_lemma #t #l a b =
logand_zeros #t #l b;
logand_ones #t #l b;
match t with
| U1 ->
assert_norm (u1 0 `logand` zeros U1 l == u1 0 /\ u1 1 `logand` zeros U1 l == u1 0);
assert_norm (u1 0 `logand` ones U1 l == u1 0 /\ u1 1 `logand` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logand_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.logand_commutative #(bits t) (v a) (v b)
let logand_spec #t #l a b =
match t with
| U1 ->
assert_norm (u1 0 `logand` u1 0 == u1 0 /\ u1 0 `logand` u1 1 == u1 0);
assert_norm (u1 1 `logand` u1 0 == u1 0 /\ u1 1 `logand` u1 1 == u1 1);
assert_norm (0 `logand_v #U1` 0 == 0 /\ 0 `logand_v #U1` 1 == 0);
assert_norm (1 `logand_v #U1` 0 == 0 /\ 1 `logand_v #U1` 1 == 1)
| _ -> ()
let logand_le #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_le (UInt.to_uint_t 8 (v a)) (UInt.to_uint_t 8 (v b))
| U16 -> UInt.logand_le (UInt.to_uint_t 16 (v a)) (UInt.to_uint_t 16 (v b))
| U32 -> UInt.logand_le (UInt.to_uint_t 32 (v a)) (UInt.to_uint_t 32 (v b))
| U64 -> UInt.logand_le (UInt.to_uint_t 64 (v a)) (UInt.to_uint_t 64 (v b))
| U128 -> UInt.logand_le (UInt.to_uint_t 128 (v a)) (UInt.to_uint_t 128 (v b))
let logand_mask #t #l a b m =
match t with
| U1 ->
assert_norm (UInt8.logand 0uy 0uy == 0uy);
assert_norm (UInt8.logand 0uy 1uy == 0uy);
assert_norm (UInt8.logand 1uy 0uy == 0uy);
assert_norm (UInt8.logand 1uy 1uy == 1uy)
| U8 -> UInt.logand_mask (UInt.to_uint_t 8 (v a)) m
| U16 -> UInt.logand_mask (UInt.to_uint_t 16 (v a)) m
| U32 -> UInt.logand_mask (UInt.to_uint_t 32 (v a)) m
| U64 -> UInt.logand_mask (UInt.to_uint_t 64 (v a)) m
| U128 -> UInt.logand_mask (UInt.to_uint_t 128 (v a)) m
[@(strict_on_arguments [0])]
let logor #t #l a b =
match t with
| U1 ->
assert_norm (UInt8.logor 0uy 0uy == 0uy);
assert_norm (UInt8.logor 0uy 1uy == 1uy);
assert_norm (UInt8.logor 1uy 0uy == 1uy);
assert_norm (UInt8.logor 1uy 1uy == 1uy);
UInt8.logor a b
| U8 -> UInt8.logor a b
| U16 -> UInt16.logor a b
| U32 -> UInt32.logor a b
| U64 -> UInt64.logor a b
| U128 -> UInt128.logor a b
| S8 -> Int8.logor a b
| S16 -> Int16.logor a b
| S32 -> Int32.logor a b
| S64 -> Int64.logor a b
| S128 -> Int128.logor a b
#push-options "--max_fuel 1"
let logor_disjoint #t #l a b m =
if m > 0 then
begin
UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a)
end
else
begin
UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)
end
#pop-options
let logor_zeros #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_1 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (Int.zero (bits t))) (v a)
let logor_ones #t #l a =
match t with
|U1 -> assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_lemma_2 #(bits t) (v a)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma (Int.logor #(bits t) (v a) (Int.ones (bits t))) (Int.ones (bits t))
let logor_lemma #t #l a b =
logor_zeros #t #l b;
logor_ones #t #l b;
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1)
| U8 | U16 | U32 | U64 | U128 -> UInt.logor_commutative #(bits t) (v a) (v b)
| S8 | S16 | S32 | S64 | S128 -> Int.nth_lemma #(bits t) (Int.logor #(bits t) (v a) (v b)) (Int.logor #(bits t) (v b) (v a))
let logor_spec #t #l a b =
match t with
| U1 ->
assert_norm(u1 0 `logor` ones U1 l == u1 1 /\ u1 1 `logor` ones U1 l == u1 1);
assert_norm(u1 0 `logor` zeros U1 l == u1 0 /\ u1 1 `logor` zeros U1 l == u1 1);
assert_norm (0 `logor_v #U1` 0 == 0 /\ 0 `logor_v #U1` 1 == 1);
assert_norm (1 `logor_v #U1` 0 == 1 /\ 1 `logor_v #U1` 1 == 1)
| _ -> ()
[@(strict_on_arguments [0])]
let lognot #t #l a =
match t with
| U1 -> UInt8.rem (UInt8.lognot a) 2uy
| U8 -> UInt8.lognot a
| U16 -> UInt16.lognot a
| U32 -> UInt32.lognot a
| U64 -> UInt64.lognot a
| U128 -> UInt128.lognot a
| S8 -> Int8.lognot a
| S16 -> Int16.lognot a
| S32 -> Int32.lognot a
| S64 -> Int64.lognot a
| S128 -> Int128.lognot a
let lognot_lemma #t #l a =
match t with
|U1 -> assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0)
| U8 | U16 | U32 | U64 | U128 ->
FStar.UInt.lognot_lemma_1 #(bits t);
UInt.nth_lemma (FStar.UInt.lognot #(bits t) (UInt.ones (bits t))) (UInt.zero (bits t))
| S8 | S16 | S32 | S64 | S128 ->
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.zero (bits t))) (Int.ones (bits t));
Int.nth_lemma (FStar.Int.lognot #(bits t) (Int.ones (bits t))) (Int.zero (bits t))
let lognot_spec #t #l a =
match t with
| U1 ->
assert_norm(lognot (u1 0) == u1 1 /\ lognot (u1 1) == u1 0);
assert_norm(lognot_v #U1 0 == 1 /\ lognot_v #U1 1 == 0)
| _ -> ()
[@(strict_on_arguments [0])]
let shift_right #t #l a b =
match t with
| U1 -> UInt8.shift_right a b
| U8 -> UInt8.shift_right a b
| U16 -> UInt16.shift_right a b
| U32 -> UInt32.shift_right a b
| U64 -> UInt64.shift_right a b
| U128 -> UInt128.shift_right a b
| S8 -> Int8.shift_arithmetic_right a b
| S16 -> Int16.shift_arithmetic_right a b
| S32 -> Int32.shift_arithmetic_right a b
| S64 -> Int64.shift_arithmetic_right a b
| S128 -> Int128.shift_arithmetic_right a b
val shift_right_value_aux_1: #n:pos{1 < n} -> a:Int.int_t n -> s:nat{n <= s} ->
Lemma (Int.shift_arithmetic_right #n a s = a / pow2 s)
let shift_right_value_aux_1 #n a s =
pow2_le_compat s n;
if a >= 0 then Int.sign_bit_positive a else Int.sign_bit_negative a
#push-options "--z3rlimit 200"
val shift_right_value_aux_2: #n:pos{1 < n} -> a:Int.int_t n ->
Lemma (Int.shift_arithmetic_right #n a 1 = a / 2)
let shift_right_value_aux_2 #n a =
if a >= 0 then
begin
Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1
end
else
begin
Int.sign_bit_negative a;
let a1 = Int.to_vec a in
let au = Int.to_uint a in
let sar = Int.shift_arithmetic_right #n a 1 in
let sar1 = Int.to_vec sar in
let sr = UInt.shift_right #n au 1 in
let sr1 = UInt.to_vec sr in
assert (Seq.equal (Seq.slice sar1 1 n) (Seq.slice sr1 1 n));
assert (Seq.equal sar1 (Seq.append (BitVector.ones_vec #1) (Seq.slice sr1 1 n)));
UInt.append_lemma #1 #(n-1) (BitVector.ones_vec #1) (Seq.slice sr1 1 n);
assert (Seq.equal (Seq.slice a1 0 (n-1)) (Seq.slice sar1 1 n));
UInt.slice_left_lemma a1 (n-1);
assert (sar + pow2 n = pow2 (n-1) + (au / 2));
pow2_double_sum (n-1);
assert (sar + pow2 (n-1) = (a + pow2 n) / 2);
pow2_double_mult (n-1);
lemma_div_plus a (pow2 (n-1)) 2;
assert (sar = a / 2)
end
val shift_right_value_aux_3: #n:pos -> a:Int.int_t n -> s:pos{s < n} ->
Lemma (ensures Int.shift_arithmetic_right #n a s = a / pow2 s)
(decreases s)
let rec shift_right_value_aux_3 #n a s =
if s = 1 then
shift_right_value_aux_2 #n a
else
begin
let a1 = Int.to_vec a in
assert (Seq.equal (BitVector.shift_arithmetic_right_vec #n a1 s)
(BitVector.shift_arithmetic_right_vec #n
(BitVector.shift_arithmetic_right_vec #n a1 (s-1)) 1));
assert (Int.shift_arithmetic_right #n a s =
Int.shift_arithmetic_right #n (Int.shift_arithmetic_right #n a (s-1)) 1);
shift_right_value_aux_3 #n a (s-1);
shift_right_value_aux_2 #n (Int.shift_arithmetic_right #n a (s-1));
assert (Int.shift_arithmetic_right #n a s = (a / pow2 (s-1)) / 2);
pow2_double_mult (s-1);
division_multiplication_lemma a (pow2 (s-1)) 2
end
let shift_right_lemma #t #l a b =
match t with
| U1 | U8 | U16 | U32 | U64 | U128 -> ()
| S8 | S16 | S32 | S64 | S128 ->
if v b = 0 then ()
else if v b >= bits t then
shift_right_value_aux_1 #(bits t) (v a) (v b)
else
shift_right_value_aux_3 #(bits t) (v a) (v b)
[@(strict_on_arguments [0])]
let shift_left #t #l a b =
match t with
| U1 -> UInt8.shift_left a b
| U8 -> UInt8.shift_left a b
| U16 -> UInt16.shift_left a b
| U32 -> UInt32.shift_left a b
| U64 -> UInt64.shift_left a b
| U128 -> UInt128.shift_left a b
| S8 -> Int8.shift_left a b
| S16 -> Int16.shift_left a b
| S32 -> Int32.shift_left a b
| S64 -> Int64.shift_left a b
| S128 -> Int128.shift_left a b
#push-options "--max_fuel 1"
let shift_left_lemma #t #l a b = ()
let rotate_right #t #l a b =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b))
let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b))
[@(strict_on_arguments [0])]
let ct_abs #t #l a =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a
#pop-options
[@(strict_on_arguments [0])]
let eq_mask #t a b =
match t with
| U1 -> lognot (logxor a b)
| U8 -> UInt8.eq_mask a b
| U16 -> UInt16.eq_mask a b
| U32 -> UInt32.eq_mask a b
| U64 -> UInt64.eq_mask a b
| U128 -> UInt128.eq_mask a b
| S8 -> Int.Cast.uint8_to_int8 (UInt8.eq_mask (to_u8 a) (to_u8 b))
| S16 -> Int.Cast.uint16_to_int16 (UInt16.eq_mask (to_u16 a) (to_u16 b))
| S32 -> Int.Cast.uint32_to_int32 (UInt32.eq_mask (to_u32 a) (to_u32 b))
| S64 -> Int.Cast.uint64_to_int64 (UInt64.eq_mask (to_u64 a) (to_u64 b))
val eq_mask_lemma_unsigned: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0)
let eq_mask_lemma_unsigned #t a b =
match t with
| U1 ->
assert_norm (
logxor (u1 0) (u1 0) == u1 0 /\ logxor (u1 0) (u1 1) == u1 1 /\
logxor (u1 1) (u1 0) == u1 1 /\ logxor (u1 1) (u1 1) == u1 0 /\
lognot (u1 1) == u1 0 /\ lognot (u1 0) == u1 1)
| U8 | U16 | U32 | U64 | U128 -> ()
#push-options "--z3rlimit 200"
val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0) | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 200,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val eq_mask_lemma_signed: #t:inttype{signed t /\ ~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a = v b then v (eq_mask a b) == ones_v t
else v (eq_mask a b) == 0) | [] | Lib.IntTypes.eq_mask_lemma_signed | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Lib.IntTypes.int_t t Lib.IntTypes.SEC -> b: Lib.IntTypes.int_t t Lib.IntTypes.SEC
-> FStar.Pervasives.Lemma
(ensures
((match Lib.IntTypes.v a = Lib.IntTypes.v b with
| true -> Lib.IntTypes.v (Lib.IntTypes.eq_mask a b) == Lib.IntTypes.ones_v t
| _ -> Lib.IntTypes.v (Lib.IntTypes.eq_mask a b) == 0)
<:
Type0)) | {
"end_col": 7,
"end_line": 860,
"start_col": 2,
"start_line": 822
} |
Prims.Tot | val cast: #t:inttype -> #l:secrecy_level
-> t':inttype
-> l':secrecy_level{PUB? l \/ SEC? l'}
-> u1:int_t t l{unsigned t' \/ range (v u1) t'}
-> u2:int_t t' l'{v u2 == v u1 @%. t'} | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cast #t #l t' l' u =
assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u | val cast: #t:inttype -> #l:secrecy_level
-> t':inttype
-> l':secrecy_level{PUB? l \/ SEC? l'}
-> u1:int_t t l{unsigned t' \/ range (v u1) t'}
-> u2:int_t t' l'{v u2 == v u1 @%. t'}
let cast #t #l t' l' u = | false | null | false | assert_norm (pow2 8 = 2 * pow2 7);
assert_norm (pow2 16 = 2 * pow2 15);
assert_norm (pow2 64 * pow2 64 = pow2 128);
assert_norm (pow2 16 * pow2 48 = pow2 64);
assert_norm (pow2 8 * pow2 56 = pow2 64);
assert_norm (pow2 32 * pow2 32 = pow2 64);
modulo_modulo_lemma (v u) (pow2 32) (pow2 32);
modulo_modulo_lemma (v u) (pow2 64) (pow2 64);
modulo_modulo_lemma (v u) (pow2 128) (pow2 64);
modulo_modulo_lemma (v u) (pow2 16) (pow2 48);
modulo_modulo_lemma (v u) (pow2 8) (pow2 56);
let open FStar.Int.Cast in
let open FStar.Int.Cast.Full in
match t, t' with
| U1, U1 -> u
| U1, U8 -> u
| U1, U16 -> uint8_to_uint16 u
| U1, U32 -> uint8_to_uint32 u
| U1, U64 -> uint8_to_uint64 u
| U1, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U1, S8 -> uint8_to_int8 u
| U1, S16 -> uint8_to_int16 u
| U1, S32 -> uint8_to_int32 u
| U1, S64 -> uint8_to_int64 u
| U1, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U8, U1 -> UInt8.rem u 2uy
| U8, U8 -> u
| U8, U16 -> uint8_to_uint16 u
| U8, U32 -> uint8_to_uint32 u
| U8, U64 -> uint8_to_uint64 u
| U8, U128 -> UInt128.uint64_to_uint128 (uint8_to_uint64 u)
| U8, S8 -> uint8_to_int8 u
| U8, S16 -> uint8_to_int16 u
| U8, S32 -> uint8_to_int32 u
| U8, S64 -> uint8_to_int64 u
| U8, S128 -> uint64_to_int128 (uint8_to_uint64 u)
| U16, U1 -> UInt8.rem (uint16_to_uint8 u) 2uy
| U16, U8 -> uint16_to_uint8 u
| U16, U16 -> u
| U16, U32 -> uint16_to_uint32 u
| U16, U64 -> uint16_to_uint64 u
| U16, U128 -> UInt128.uint64_to_uint128 (uint16_to_uint64 u)
| U16, S8 -> uint16_to_int8 u
| U16, S16 -> uint16_to_int16 u
| U16, S32 -> uint16_to_int32 u
| U16, S64 -> uint16_to_int64 u
| U16, S128 -> uint64_to_int128 (uint16_to_uint64 u)
| U32, U1 -> UInt8.rem (uint32_to_uint8 u) 2uy
| U32, U8 -> uint32_to_uint8 u
| U32, U16 -> uint32_to_uint16 u
| U32, U32 -> u
| U32, U64 -> uint32_to_uint64 u
| U32, U128 -> UInt128.uint64_to_uint128 (uint32_to_uint64 u)
| U32, S8 -> uint32_to_int8 u
| U32, S16 -> uint32_to_int16 u
| U32, S32 -> uint32_to_int32 u
| U32, S64 -> uint32_to_int64 u
| U32, S128 -> uint64_to_int128 (uint32_to_uint64 u)
| U64, U1 -> UInt8.rem (uint64_to_uint8 u) 2uy
| U64, U8 -> uint64_to_uint8 u
| U64, U16 -> uint64_to_uint16 u
| U64, U32 -> uint64_to_uint32 u
| U64, U64 -> u
| U64, U128 -> UInt128.uint64_to_uint128 u
| U64, S8 -> uint64_to_int8 u
| U64, S16 -> uint64_to_int16 u
| U64, S32 -> uint64_to_int32 u
| U64, S64 -> uint64_to_int64 u
| U64, S128 -> uint64_to_int128 u
| U128, U1 -> UInt8.rem (uint64_to_uint8 (uint128_to_uint64 u)) 2uy
| U128, U8 -> uint64_to_uint8 (UInt128.uint128_to_uint64 u)
| U128, U16 -> uint64_to_uint16 (UInt128.uint128_to_uint64 u)
| U128, U32 -> uint64_to_uint32 (UInt128.uint128_to_uint64 u)
| U128, U64 -> UInt128.uint128_to_uint64 u
| U128, U128 -> u
| U128, S8 -> uint64_to_int8 (UInt128.uint128_to_uint64 u)
| U128, S16 -> uint64_to_int16 (UInt128.uint128_to_uint64 u)
| U128, S32 -> uint64_to_int32 (UInt128.uint128_to_uint64 u)
| U128, S64 -> uint64_to_int64 (UInt128.uint128_to_uint64 u)
| U128, S128 -> uint128_to_int128 u
| S8, U1 -> UInt8.rem (int8_to_uint8 u) 2uy
| S8, U8 -> int8_to_uint8 u
| S8, U16 -> int8_to_uint16 u
| S8, U32 -> int8_to_uint32 u
| S8, U64 -> int8_to_uint64 u
| S8, U128 -> int64_to_uint128 (int8_to_int64 u)
| S8, S8 -> u
| S8, S16 -> int8_to_int16 u
| S8, S32 -> int8_to_int32 u
| S8, S64 -> int8_to_int64 u
| S8, S128 -> int64_to_int128 (int8_to_int64 u)
| S16, U1 -> UInt8.rem (int16_to_uint8 u) 2uy
| S16, U8 -> int16_to_uint8 u
| S16, U16 -> int16_to_uint16 u
| S16, U32 -> int16_to_uint32 u
| S16, U64 -> int16_to_uint64 u
| S16, U128 -> int64_to_uint128 (int16_to_int64 u)
| S16, S8 -> int16_to_int8 u
| S16, S16 -> u
| S16, S32 -> int16_to_int32 u
| S16, S64 -> int16_to_int64 u
| S16, S128 -> int64_to_int128 (int16_to_int64 u)
| S32, U1 -> UInt8.rem (int32_to_uint8 u) 2uy
| S32, U8 -> int32_to_uint8 u
| S32, U16 -> int32_to_uint16 u
| S32, U32 -> int32_to_uint32 u
| S32, U64 -> int32_to_uint64 u
| S32, U128 -> int64_to_uint128 (int32_to_int64 u)
| S32, S8 -> int32_to_int8 u
| S32, S16 -> int32_to_int16 u
| S32, S32 -> u
| S32, S64 -> int32_to_int64 u
| S32, S128 -> int64_to_int128 (int32_to_int64 u)
| S64, U1 -> UInt8.rem (int64_to_uint8 u) 2uy
| S64, U8 -> int64_to_uint8 u
| S64, U16 -> int64_to_uint16 u
| S64, U32 -> int64_to_uint32 u
| S64, U64 -> int64_to_uint64 u
| S64, U128 -> int64_to_uint128 u
| S64, S8 -> int64_to_int8 u
| S64, S16 -> int64_to_int16 u
| S64, S32 -> int64_to_int32 u
| S64, S64 -> u
| S64, S128 -> int64_to_int128 u
| S128, U1 -> UInt8.rem (uint64_to_uint8 (int128_to_uint64 u)) 2uy
| S128, U8 -> uint64_to_uint8 (int128_to_uint64 u)
| S128, U16 -> uint64_to_uint16 (int128_to_uint64 u)
| S128, U32 -> uint64_to_uint32 (int128_to_uint64 u)
| S128, U64 -> int128_to_uint64 u
| S128, U128 -> int128_to_uint128 u
| S128, S8 -> uint64_to_int8 (int128_to_uint64 u)
| S128, S16 -> uint64_to_int16 (int128_to_uint64 u)
| S128, S32 -> uint64_to_int32 (int128_to_uint64 u)
| S128, S64 -> uint64_to_int64 (int128_to_uint64 u)
| S128, S128 -> u | {
"checked_file": "Lib.IntTypes.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.UInt128.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Int128.fsti.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.Int.Cast.fst.checked",
"FStar.Int.fsti.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "Lib.IntTypes.fst"
} | [
"total"
] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Prims.l_or",
"Prims.b2t",
"Lib.IntTypes.uu___is_PUB",
"Lib.IntTypes.uu___is_SEC",
"Lib.IntTypes.int_t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.range",
"Lib.IntTypes.v",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Int.Cast.uint8_to_uint16",
"FStar.Int.Cast.uint8_to_uint32",
"FStar.Int.Cast.uint8_to_uint64",
"FStar.UInt128.uint64_to_uint128",
"FStar.Int.Cast.uint8_to_int8",
"FStar.Int.Cast.uint8_to_int16",
"FStar.Int.Cast.uint8_to_int32",
"FStar.Int.Cast.uint8_to_int64",
"Lib.IntTypes.uint64_to_int128",
"FStar.UInt8.rem",
"FStar.UInt8.__uint_to_t",
"FStar.Int.Cast.uint16_to_uint8",
"FStar.Int.Cast.uint16_to_uint32",
"FStar.Int.Cast.uint16_to_uint64",
"FStar.Int.Cast.uint16_to_int8",
"FStar.Int.Cast.uint16_to_int16",
"FStar.Int.Cast.uint16_to_int32",
"FStar.Int.Cast.uint16_to_int64",
"FStar.Int.Cast.uint32_to_uint8",
"FStar.Int.Cast.uint32_to_uint16",
"FStar.Int.Cast.uint32_to_uint64",
"FStar.Int.Cast.uint32_to_int8",
"FStar.Int.Cast.uint32_to_int16",
"FStar.Int.Cast.uint32_to_int32",
"FStar.Int.Cast.uint32_to_int64",
"FStar.Int.Cast.uint64_to_uint8",
"FStar.Int.Cast.uint64_to_uint16",
"FStar.Int.Cast.uint64_to_uint32",
"FStar.Int.Cast.uint64_to_int8",
"FStar.Int.Cast.uint64_to_int16",
"FStar.Int.Cast.uint64_to_int32",
"FStar.Int.Cast.uint64_to_int64",
"FStar.Int.Cast.Full.uint128_to_uint64",
"FStar.UInt128.uint128_to_uint64",
"Lib.IntTypes.uint128_to_int128",
"FStar.Int.Cast.int8_to_uint8",
"FStar.Int.Cast.int8_to_uint16",
"FStar.Int.Cast.int8_to_uint32",
"FStar.Int.Cast.int8_to_uint64",
"Lib.IntTypes.int64_to_uint128",
"FStar.Int.Cast.int8_to_int64",
"FStar.Int.Cast.int8_to_int16",
"FStar.Int.Cast.int8_to_int32",
"Lib.IntTypes.int64_to_int128",
"FStar.Int.Cast.int16_to_uint8",
"FStar.Int.Cast.int16_to_uint16",
"FStar.Int.Cast.int16_to_uint32",
"FStar.Int.Cast.int16_to_uint64",
"FStar.Int.Cast.int16_to_int64",
"FStar.Int.Cast.int16_to_int8",
"FStar.Int.Cast.int16_to_int32",
"FStar.Int.Cast.int32_to_uint8",
"FStar.Int.Cast.int32_to_uint16",
"FStar.Int.Cast.int32_to_uint32",
"FStar.Int.Cast.int32_to_uint64",
"FStar.Int.Cast.int32_to_int64",
"FStar.Int.Cast.int32_to_int8",
"FStar.Int.Cast.int32_to_int16",
"FStar.Int.Cast.int64_to_uint8",
"FStar.Int.Cast.int64_to_uint16",
"FStar.Int.Cast.int64_to_uint32",
"FStar.Int.Cast.int64_to_uint64",
"FStar.Int.Cast.int64_to_int8",
"FStar.Int.Cast.int64_to_int16",
"FStar.Int.Cast.int64_to_int32",
"Lib.IntTypes.int128_to_uint64",
"Lib.IntTypes.int128_to_uint128",
"Prims.eq2",
"Prims.int",
"Lib.IntTypes.op_At_Percent_Dot",
"Prims.unit",
"FStar.Math.Lemmas.modulo_modulo_lemma",
"Prims.pow2",
"FStar.Pervasives.assert_norm",
"Prims.op_Equality",
"FStar.Mul.op_Star"
] | [] | module Lib.IntTypes
open FStar.Math.Lemmas
#push-options "--max_fuel 0 --max_ifuel 1 --z3rlimit 200"
let pow2_2 _ = assert_norm (pow2 2 = 4)
let pow2_3 _ = assert_norm (pow2 3 = 8)
let pow2_4 _ = assert_norm (pow2 4 = 16)
let pow2_127 _ = assert_norm (pow2 127 = 0x80000000000000000000000000000000)
let bits_numbytes t = ()
let sec_int_t t = pub_int_t t
let sec_int_v #t u = pub_int_v u
let secret #t x = x
[@(strict_on_arguments [0])]
let mk_int #t #l x =
match t with
| U1 -> UInt8.uint_to_t x
| U8 -> UInt8.uint_to_t x
| U16 -> UInt16.uint_to_t x
| U32 -> UInt32.uint_to_t x
| U64 -> UInt64.uint_to_t x
| U128 -> UInt128.uint_to_t x
| S8 -> Int8.int_to_t x
| S16 -> Int16.int_to_t x
| S32 -> Int32.int_to_t x
| S64 -> Int64.int_to_t x
| S128 -> Int128.int_to_t x
val v_extensionality:
#t:inttype
-> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma
(requires v a == v b)
(ensures a == b)
let v_extensionality #t #l a b =
match t with
| U1 -> ()
| U8 -> UInt8.v_inj a b
| U16 -> UInt16.v_inj a b
| U32 -> UInt32.v_inj a b
| U64 -> UInt64.v_inj a b
| U128 -> UInt128.v_inj a b
| S8 -> Int8.v_inj a b
| S16 -> Int16.v_inj a b
| S32 -> Int32.v_inj a b
| S64 -> Int64.v_inj a b
| S128 -> Int128.v_inj a b
let v_injective #t #l a =
v_extensionality a (mk_int (v a))
let v_mk_int #t #l n = ()
let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n)
// KaRaMeL will extract this to FStar_Int128_int_to_t, which isn't provided
// We'll need to have FStar.Int128.int64_to_int128 to support int128_t literals
let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n
let size_to_uint32 x = x
let size_to_uint64 x = Int.Cast.uint32_to_uint64 x
let byte_to_uint8 x = x
let byte_to_int8 x = Int.Cast.uint8_to_int8 x
let op_At_Percent = Int.op_At_Percent
// FStar.UInt128 gets special treatment in KaRaMeL. There is no
// equivalent for FStar.Int128 at the moment, so we use the three
// assumed cast operators below.
//
// Using them will fail at runtime with an informative message.
// The commented-out implementations show that they are realizable.
//
// When support for `FStar.Int128` is added KaRaMeL, these casts must
// be added as special cases. When using builtin compiler support for
// `int128_t`, they can be implemented directly as C casts without
// undefined or implementation-defined behaviour.
assume
val uint128_to_int128: a:UInt128.t{v a <= maxint S128} -> b:Int128.t{Int128.v b == UInt128.v a}
//let uint128_to_int128 a = Int128.int_to_t (v a)
assume
val int128_to_uint128: a:Int128.t -> b:UInt128.t{UInt128.v b == Int128.v a % pow2 128}
//let int128_to_uint128 a = mk_int (v a % pow2 128)
assume
val int64_to_int128: a:Int64.t -> b:Int128.t{Int128.v b == Int64.v a}
//let int64_to_int128 a = Int128.int_to_t (v a)
val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.v a}
let uint64_to_int128 a = uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a)
val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128}
let int64_to_uint128 a = int128_to_uint128 (int64_to_int128 a)
val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64}
let int128_to_uint64 a = Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a)
#push-options "--z3rlimit 1000"
[@(strict_on_arguments [0;2])] | false | false | Lib.IntTypes.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 1000,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cast: #t:inttype -> #l:secrecy_level
-> t':inttype
-> l':secrecy_level{PUB? l \/ SEC? l'}
-> u1:int_t t l{unsigned t' \/ range (v u1) t'}
-> u2:int_t t' l'{v u2 == v u1 @%. t'} | [] | Lib.IntTypes.cast | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
t': Lib.IntTypes.inttype ->
l': Lib.IntTypes.secrecy_level{PUB? l \/ SEC? l'} ->
u1:
Lib.IntTypes.int_t t l {Lib.IntTypes.unsigned t' \/ Lib.IntTypes.range (Lib.IntTypes.v u1) t'}
-> u2: Lib.IntTypes.int_t t' l' {Lib.IntTypes.v u2 == Lib.IntTypes.v u1 @%. t'} | {
"end_col": 20,
"end_line": 261,
"start_col": 2,
"start_line": 117
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52.Lemmas",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.K256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.K256.Scalar",
"short_module": "QA"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "KL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lbytes len = lbuffer uint8 len | let lbytes len = | false | null | false | lbuffer uint8 len | {
"checked_file": "Hacl.Impl.K256.Verify.fst.checked",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Lemmas.fsti.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Qinv.fst.checked",
"Hacl.Impl.K256.PointMul.fsti.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"Hacl.Impl.K256.GLV.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.K256.Verify.fst"
} | [
"total"
] | [
"Lib.IntTypes.size_t",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8"
] | [] | module Hacl.Impl.K256.Verify
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module KL = Spec.K256.Lemmas
open Hacl.K256.Field
open Hacl.Impl.K256.Point
open Hacl.Impl.K256.PointMul
open Hacl.Impl.K256.GLV
module QA = Hacl.K256.Scalar
module QI = Hacl.Impl.K256.Qinv
module BL = Hacl.Spec.K256.Field52.Lemmas
module BSeq = Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | false | true | Hacl.Impl.K256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lbytes : len: Lib.IntTypes.size_t -> Type0 | [] | Hacl.Impl.K256.Verify.lbytes | {
"file_name": "code/k256/Hacl.Impl.K256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Lib.IntTypes.size_t -> Type0 | {
"end_col": 34,
"end_line": 28,
"start_col": 17,
"start_line": 28
} |
|
FStar.HyperStack.ST.Stack | val load_signature (r_q s_q:QA.qelem) (signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h signature /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q signature /\ disjoint s_q signature)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let sign_r = gsub signature 0ul 32ul in
let sign_s = gsub signature 32ul 32ul in
let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
QA.qas_nat h1 r_q = r_q_nat /\ QA.qas_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.q && 0 < s_q_nat && s_q_nat < S.q))) | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52.Lemmas",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.K256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.K256.Scalar",
"short_module": "QA"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "KL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let load_signature r_q s_q signature =
let is_r_valid = QA.load_qelem_vartime r_q (sub signature 0ul 32ul) in
let is_s_valid = QA.load_qelem_vartime s_q (sub signature 32ul 32ul) in
is_r_valid && is_s_valid | val load_signature (r_q s_q:QA.qelem) (signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h signature /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q signature /\ disjoint s_q signature)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let sign_r = gsub signature 0ul 32ul in
let sign_s = gsub signature 32ul 32ul in
let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
QA.qas_nat h1 r_q = r_q_nat /\ QA.qas_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.q && 0 < s_q_nat && s_q_nat < S.q)))
let load_signature r_q s_q signature = | true | null | false | let is_r_valid = QA.load_qelem_vartime r_q (sub signature 0ul 32ul) in
let is_s_valid = QA.load_qelem_vartime s_q (sub signature 32ul 32ul) in
is_r_valid && is_s_valid | {
"checked_file": "Hacl.Impl.K256.Verify.fst.checked",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Lemmas.fsti.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Qinv.fst.checked",
"Hacl.Impl.K256.PointMul.fsti.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"Hacl.Impl.K256.GLV.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.K256.Verify.fst"
} | [] | [
"Hacl.K256.Scalar.qelem",
"Hacl.Impl.K256.Verify.lbytes",
"FStar.UInt32.__uint_to_t",
"Prims.op_AmpAmp",
"Prims.bool",
"Hacl.K256.Scalar.load_qelem_vartime",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"Lib.IntTypes.uint8"
] | [] | module Hacl.Impl.K256.Verify
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module KL = Spec.K256.Lemmas
open Hacl.K256.Field
open Hacl.Impl.K256.Point
open Hacl.Impl.K256.PointMul
open Hacl.Impl.K256.GLV
module QA = Hacl.K256.Scalar
module QI = Hacl.Impl.K256.Qinv
module BL = Hacl.Spec.K256.Field52.Lemmas
module BSeq = Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
inline_for_extraction noextract
val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q))
let ecdsa_verify_get_u12 u1 u2 r s z =
push_frame ();
let sinv = QA.create_qelem () in
QI.qinv sinv s;
QA.qmul u1 z sinv;
QA.qmul u2 r sinv;
pop_frame ()
val fmul_eq_vartime (r z x: felem) : Stack bool
(requires fun h ->
live h r /\ live h z /\ live h x /\ eq_or_disjoint r z /\
felem_fits5 (as_felem5 h r) (2,2,2,2,2) /\ as_nat h r < S.prime /\
inv_lazy_reduced2 h z /\ inv_fully_reduced h x)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == (S.fmul (as_nat h0 r) (feval h0 z) = as_nat h0 x))
[@CInline]
let fmul_eq_vartime r z x =
push_frame ();
let tmp = create_felem () in
fmul tmp r z;
let h1 = ST.get () in
fnormalize tmp tmp;
let h2 = ST.get () in
BL.normalize5_lemma (1,1,1,1,2) (as_felem5 h1 tmp);
assert (inv_fully_reduced h2 tmp);
let b = is_felem_eq_vartime tmp x in
pop_frame ();
b
inline_for_extraction noextract
val ecdsa_verify_avoid_finv: p:point -> r:QA.qelem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ QA.qe_lt_q h r /\ 0 < QA.qas_nat h r /\
not (S.is_proj_point_at_inf (point_eval h p)))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = point_eval h0 p in
b <==> (S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r)))
let ecdsa_verify_avoid_finv p r =
let h0 = ST.get () in
let x, y, z = getx p, gety p, getz p in
push_frame ();
let r_bytes = create 32ul (u8 0) in
let r_fe = create_felem () in
let tmp_q = create_felem () in
let tmp_x = create_felem () in
QA.store_qelem r_bytes r;
load_felem r_fe r_bytes;
let h1 = ST.get () in
//assert (inv_fully_reduced h1 r_fe);
//assert (as_nat h1 r_fe == qas_nat h1 r);
let h2 = ST.get () in
fnormalize tmp_x x;
let h3 = ST.get () in
BL.normalize5_lemma (1,1,1,1,2) (as_felem5 h2 x);
//assert (inv_fully_reduced h3 tmp_x);
//assert (inv_lazy_reduced2 h3 z);
let is_rz_x = fmul_eq_vartime r_fe z tmp_x in
//assert (is_rz_x == (S.fmul (as_nat h3 r_fe) (feval h3 z) = as_nat h3 tmp_x));
let res : bool =
if not is_rz_x then begin
let is_r_lt_p_m_q = is_felem_lt_prime_minus_order_vartime r_fe in
if is_r_lt_p_m_q then begin
assert (as_nat h1 r_fe < S.prime - S.q);
make_u52_5 tmp_q (make_order_k256 ());
let h4 = ST.get () in
BL.add5_lemma (1,1,1,1,1) (1,1,1,1,1) (as_felem5 h4 r_fe) (as_felem5 h4 tmp_q);
fadd tmp_q r_fe tmp_q;
fmul_eq_vartime tmp_q z tmp_x end
//assert (is_rqz_x == (S.fmul (feval h5 tmp) (feval h5 z) = as_nat h5 tmp_x));
else false end
else true in
pop_frame ();
KL.ecdsa_verify_avoid_finv (point_eval h0 p) (QA.qas_nat h0 r);
assert (res <==> (S.fmul (feval h0 x) (S.finv (feval h0 z)) % S.q = QA.qas_nat h0 r));
let h5 = ST.get () in
assert (modifies0 h0 h5);
res
inline_for_extraction noextract
val ecdsa_verify_cmpr: r:QA.qelem -> pk:point -> u1:QA.qelem -> u2:QA.qelem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ QA.qas_nat h u1 < S.q /\ QA.qas_nat h u2 < S.q /\
0 < QA.qas_nat h r /\ QA.qas_nat h r < S.q)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk) in
b <==> (if S.is_proj_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r)))
let ecdsa_verify_cmpr r pk u1 u2 =
push_frame ();
let res = create_point () in
let h0 = ST.get () in
point_mul_g_double_split_lambda_vartime res u1 u2 pk;
let h1 = ST.get () in
assert (S.to_aff_point (point_eval h1 res) ==
S.to_aff_point (S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk)));
KL.lemma_aff_is_point_at_inf (point_eval h1 res);
KL.lemma_aff_is_point_at_inf (S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk));
let b =
if is_proj_point_at_inf_vartime res then false
else ecdsa_verify_avoid_finv res r in
pop_frame ();
b
inline_for_extraction noextract
val load_signature (r_q s_q:QA.qelem) (signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h signature /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q signature /\ disjoint s_q signature)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let sign_r = gsub signature 0ul 32ul in
let sign_s = gsub signature 32ul 32ul in
let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
QA.qas_nat h1 r_q = r_q_nat /\ QA.qas_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.q && 0 < s_q_nat && s_q_nat < S.q))) | false | false | Hacl.Impl.K256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val load_signature (r_q s_q:QA.qelem) (signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h signature /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q signature /\ disjoint s_q signature)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let sign_r = gsub signature 0ul 32ul in
let sign_s = gsub signature 32ul 32ul in
let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
QA.qas_nat h1 r_q = r_q_nat /\ QA.qas_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.q && 0 < s_q_nat && s_q_nat < S.q))) | [] | Hacl.Impl.K256.Verify.load_signature | {
"file_name": "code/k256/Hacl.Impl.K256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
r_q: Hacl.K256.Scalar.qelem ->
s_q: Hacl.K256.Scalar.qelem ->
signature: Hacl.Impl.K256.Verify.lbytes 64ul
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 26,
"end_line": 183,
"start_col": 38,
"start_line": 180
} |
FStar.HyperStack.ST.Stack | val fmul_eq_vartime (r z x: felem) : Stack bool
(requires fun h ->
live h r /\ live h z /\ live h x /\ eq_or_disjoint r z /\
felem_fits5 (as_felem5 h r) (2,2,2,2,2) /\ as_nat h r < S.prime /\
inv_lazy_reduced2 h z /\ inv_fully_reduced h x)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == (S.fmul (as_nat h0 r) (feval h0 z) = as_nat h0 x)) | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52.Lemmas",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.K256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.K256.Scalar",
"short_module": "QA"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "KL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fmul_eq_vartime r z x =
push_frame ();
let tmp = create_felem () in
fmul tmp r z;
let h1 = ST.get () in
fnormalize tmp tmp;
let h2 = ST.get () in
BL.normalize5_lemma (1,1,1,1,2) (as_felem5 h1 tmp);
assert (inv_fully_reduced h2 tmp);
let b = is_felem_eq_vartime tmp x in
pop_frame ();
b | val fmul_eq_vartime (r z x: felem) : Stack bool
(requires fun h ->
live h r /\ live h z /\ live h x /\ eq_or_disjoint r z /\
felem_fits5 (as_felem5 h r) (2,2,2,2,2) /\ as_nat h r < S.prime /\
inv_lazy_reduced2 h z /\ inv_fully_reduced h x)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == (S.fmul (as_nat h0 r) (feval h0 z) = as_nat h0 x))
let fmul_eq_vartime r z x = | true | null | false | push_frame ();
let tmp = create_felem () in
fmul tmp r z;
let h1 = ST.get () in
fnormalize tmp tmp;
let h2 = ST.get () in
BL.normalize5_lemma (1, 1, 1, 1, 2) (as_felem5 h1 tmp);
assert (inv_fully_reduced h2 tmp);
let b = is_felem_eq_vartime tmp x in
pop_frame ();
b | {
"checked_file": "Hacl.Impl.K256.Verify.fst.checked",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Lemmas.fsti.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Qinv.fst.checked",
"Hacl.Impl.K256.PointMul.fsti.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"Hacl.Impl.K256.GLV.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.K256.Verify.fst"
} | [] | [
"Hacl.K256.Field.felem",
"Prims.bool",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Hacl.K256.Field.is_felem_eq_vartime",
"Prims._assert",
"Hacl.K256.Field.inv_fully_reduced",
"Hacl.Spec.K256.Field52.Lemmas.normalize5_lemma",
"FStar.Pervasives.Native.Mktuple5",
"Prims.nat",
"Hacl.K256.Field.as_felem5",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.K256.Field.fnormalize",
"Hacl.K256.Field.fmul",
"Hacl.K256.Field.create_felem",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.K256.Verify
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module KL = Spec.K256.Lemmas
open Hacl.K256.Field
open Hacl.Impl.K256.Point
open Hacl.Impl.K256.PointMul
open Hacl.Impl.K256.GLV
module QA = Hacl.K256.Scalar
module QI = Hacl.Impl.K256.Qinv
module BL = Hacl.Spec.K256.Field52.Lemmas
module BSeq = Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
inline_for_extraction noextract
val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q))
let ecdsa_verify_get_u12 u1 u2 r s z =
push_frame ();
let sinv = QA.create_qelem () in
QI.qinv sinv s;
QA.qmul u1 z sinv;
QA.qmul u2 r sinv;
pop_frame ()
val fmul_eq_vartime (r z x: felem) : Stack bool
(requires fun h ->
live h r /\ live h z /\ live h x /\ eq_or_disjoint r z /\
felem_fits5 (as_felem5 h r) (2,2,2,2,2) /\ as_nat h r < S.prime /\
inv_lazy_reduced2 h z /\ inv_fully_reduced h x)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == (S.fmul (as_nat h0 r) (feval h0 z) = as_nat h0 x))
[@CInline] | false | false | Hacl.Impl.K256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fmul_eq_vartime (r z x: felem) : Stack bool
(requires fun h ->
live h r /\ live h z /\ live h x /\ eq_or_disjoint r z /\
felem_fits5 (as_felem5 h r) (2,2,2,2,2) /\ as_nat h r < S.prime /\
inv_lazy_reduced2 h z /\ inv_fully_reduced h x)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == (S.fmul (as_nat h0 r) (feval h0 z) = as_nat h0 x)) | [] | Hacl.Impl.K256.Verify.fmul_eq_vartime | {
"file_name": "code/k256/Hacl.Impl.K256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | r: Hacl.K256.Field.felem -> z: Hacl.K256.Field.felem -> x: Hacl.K256.Field.felem
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 3,
"end_line": 71,
"start_col": 2,
"start_line": 61
} |
FStar.HyperStack.ST.Stack | val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q)) | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52.Lemmas",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.K256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.K256.Scalar",
"short_module": "QA"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "KL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ecdsa_verify_get_u12 u1 u2 r s z =
push_frame ();
let sinv = QA.create_qelem () in
QI.qinv sinv s;
QA.qmul u1 z sinv;
QA.qmul u2 r sinv;
pop_frame () | val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q))
let ecdsa_verify_get_u12 u1 u2 r s z = | true | null | false | push_frame ();
let sinv = QA.create_qelem () in
QI.qinv sinv s;
QA.qmul u1 z sinv;
QA.qmul u2 r sinv;
pop_frame () | {
"checked_file": "Hacl.Impl.K256.Verify.fst.checked",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Lemmas.fsti.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Qinv.fst.checked",
"Hacl.Impl.K256.PointMul.fsti.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"Hacl.Impl.K256.GLV.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.K256.Verify.fst"
} | [] | [
"Hacl.K256.Scalar.qelem",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.K256.Scalar.qmul",
"Hacl.Impl.K256.Qinv.qinv",
"Hacl.K256.Scalar.create_qelem",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.K256.Verify
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module KL = Spec.K256.Lemmas
open Hacl.K256.Field
open Hacl.Impl.K256.Point
open Hacl.Impl.K256.PointMul
open Hacl.Impl.K256.GLV
module QA = Hacl.K256.Scalar
module QI = Hacl.Impl.K256.Qinv
module BL = Hacl.Spec.K256.Field52.Lemmas
module BSeq = Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
inline_for_extraction noextract
val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q)) | false | false | Hacl.Impl.K256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q)) | [] | Hacl.Impl.K256.Verify.ecdsa_verify_get_u12 | {
"file_name": "code/k256/Hacl.Impl.K256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
u1: Hacl.K256.Scalar.qelem ->
u2: Hacl.K256.Scalar.qelem ->
r: Hacl.K256.Scalar.qelem ->
s: Hacl.K256.Scalar.qelem ->
z: Hacl.K256.Scalar.qelem
-> FStar.HyperStack.ST.Stack Prims.unit | {
"end_col": 14,
"end_line": 48,
"start_col": 2,
"start_line": 43
} |
FStar.HyperStack.ST.Stack | val ecdsa_verify_cmpr: r:QA.qelem -> pk:point -> u1:QA.qelem -> u2:QA.qelem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ QA.qas_nat h u1 < S.q /\ QA.qas_nat h u2 < S.q /\
0 < QA.qas_nat h r /\ QA.qas_nat h r < S.q)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk) in
b <==> (if S.is_proj_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r))) | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52.Lemmas",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.K256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.K256.Scalar",
"short_module": "QA"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "KL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ecdsa_verify_cmpr r pk u1 u2 =
push_frame ();
let res = create_point () in
let h0 = ST.get () in
point_mul_g_double_split_lambda_vartime res u1 u2 pk;
let h1 = ST.get () in
assert (S.to_aff_point (point_eval h1 res) ==
S.to_aff_point (S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk)));
KL.lemma_aff_is_point_at_inf (point_eval h1 res);
KL.lemma_aff_is_point_at_inf (S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk));
let b =
if is_proj_point_at_inf_vartime res then false
else ecdsa_verify_avoid_finv res r in
pop_frame ();
b | val ecdsa_verify_cmpr: r:QA.qelem -> pk:point -> u1:QA.qelem -> u2:QA.qelem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ QA.qas_nat h u1 < S.q /\ QA.qas_nat h u2 < S.q /\
0 < QA.qas_nat h r /\ QA.qas_nat h r < S.q)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk) in
b <==> (if S.is_proj_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r)))
let ecdsa_verify_cmpr r pk u1 u2 = | true | null | false | push_frame ();
let res = create_point () in
let h0 = ST.get () in
point_mul_g_double_split_lambda_vartime res u1 u2 pk;
let h1 = ST.get () in
assert (S.to_aff_point (point_eval h1 res) ==
S.to_aff_point (S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2) (point_eval h0 pk)));
KL.lemma_aff_is_point_at_inf (point_eval h1 res);
KL.lemma_aff_is_point_at_inf (S.point_mul_double_g (QA.qas_nat h0 u1)
(QA.qas_nat h0 u2)
(point_eval h0 pk));
let b = if is_proj_point_at_inf_vartime res then false else ecdsa_verify_avoid_finv res r in
pop_frame ();
b | {
"checked_file": "Hacl.Impl.K256.Verify.fst.checked",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Lemmas.fsti.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Qinv.fst.checked",
"Hacl.Impl.K256.PointMul.fsti.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"Hacl.Impl.K256.GLV.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.K256.Verify.fst"
} | [] | [
"Hacl.K256.Scalar.qelem",
"Hacl.Impl.K256.Point.point",
"Prims.bool",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Hacl.Impl.K256.Verify.ecdsa_verify_avoid_finv",
"Hacl.Impl.K256.Point.is_proj_point_at_inf_vartime",
"Spec.K256.Lemmas.lemma_aff_is_point_at_inf",
"Spec.K256.point_mul_double_g",
"Hacl.K256.Scalar.qas_nat",
"Hacl.Impl.K256.Point.point_eval",
"Prims._assert",
"Prims.eq2",
"Spec.K256.PointOps.aff_point",
"Spec.K256.PointOps.to_aff_point",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.K256.GLV.point_mul_g_double_split_lambda_vartime",
"Hacl.Impl.K256.Point.create_point",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.K256.Verify
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module KL = Spec.K256.Lemmas
open Hacl.K256.Field
open Hacl.Impl.K256.Point
open Hacl.Impl.K256.PointMul
open Hacl.Impl.K256.GLV
module QA = Hacl.K256.Scalar
module QI = Hacl.Impl.K256.Qinv
module BL = Hacl.Spec.K256.Field52.Lemmas
module BSeq = Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
inline_for_extraction noextract
val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q))
let ecdsa_verify_get_u12 u1 u2 r s z =
push_frame ();
let sinv = QA.create_qelem () in
QI.qinv sinv s;
QA.qmul u1 z sinv;
QA.qmul u2 r sinv;
pop_frame ()
val fmul_eq_vartime (r z x: felem) : Stack bool
(requires fun h ->
live h r /\ live h z /\ live h x /\ eq_or_disjoint r z /\
felem_fits5 (as_felem5 h r) (2,2,2,2,2) /\ as_nat h r < S.prime /\
inv_lazy_reduced2 h z /\ inv_fully_reduced h x)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == (S.fmul (as_nat h0 r) (feval h0 z) = as_nat h0 x))
[@CInline]
let fmul_eq_vartime r z x =
push_frame ();
let tmp = create_felem () in
fmul tmp r z;
let h1 = ST.get () in
fnormalize tmp tmp;
let h2 = ST.get () in
BL.normalize5_lemma (1,1,1,1,2) (as_felem5 h1 tmp);
assert (inv_fully_reduced h2 tmp);
let b = is_felem_eq_vartime tmp x in
pop_frame ();
b
inline_for_extraction noextract
val ecdsa_verify_avoid_finv: p:point -> r:QA.qelem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ QA.qe_lt_q h r /\ 0 < QA.qas_nat h r /\
not (S.is_proj_point_at_inf (point_eval h p)))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = point_eval h0 p in
b <==> (S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r)))
let ecdsa_verify_avoid_finv p r =
let h0 = ST.get () in
let x, y, z = getx p, gety p, getz p in
push_frame ();
let r_bytes = create 32ul (u8 0) in
let r_fe = create_felem () in
let tmp_q = create_felem () in
let tmp_x = create_felem () in
QA.store_qelem r_bytes r;
load_felem r_fe r_bytes;
let h1 = ST.get () in
//assert (inv_fully_reduced h1 r_fe);
//assert (as_nat h1 r_fe == qas_nat h1 r);
let h2 = ST.get () in
fnormalize tmp_x x;
let h3 = ST.get () in
BL.normalize5_lemma (1,1,1,1,2) (as_felem5 h2 x);
//assert (inv_fully_reduced h3 tmp_x);
//assert (inv_lazy_reduced2 h3 z);
let is_rz_x = fmul_eq_vartime r_fe z tmp_x in
//assert (is_rz_x == (S.fmul (as_nat h3 r_fe) (feval h3 z) = as_nat h3 tmp_x));
let res : bool =
if not is_rz_x then begin
let is_r_lt_p_m_q = is_felem_lt_prime_minus_order_vartime r_fe in
if is_r_lt_p_m_q then begin
assert (as_nat h1 r_fe < S.prime - S.q);
make_u52_5 tmp_q (make_order_k256 ());
let h4 = ST.get () in
BL.add5_lemma (1,1,1,1,1) (1,1,1,1,1) (as_felem5 h4 r_fe) (as_felem5 h4 tmp_q);
fadd tmp_q r_fe tmp_q;
fmul_eq_vartime tmp_q z tmp_x end
//assert (is_rqz_x == (S.fmul (feval h5 tmp) (feval h5 z) = as_nat h5 tmp_x));
else false end
else true in
pop_frame ();
KL.ecdsa_verify_avoid_finv (point_eval h0 p) (QA.qas_nat h0 r);
assert (res <==> (S.fmul (feval h0 x) (S.finv (feval h0 z)) % S.q = QA.qas_nat h0 r));
let h5 = ST.get () in
assert (modifies0 h0 h5);
res
inline_for_extraction noextract
val ecdsa_verify_cmpr: r:QA.qelem -> pk:point -> u1:QA.qelem -> u2:QA.qelem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ QA.qas_nat h u1 < S.q /\ QA.qas_nat h u2 < S.q /\
0 < QA.qas_nat h r /\ QA.qas_nat h r < S.q)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk) in
b <==> (if S.is_proj_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r))) | false | false | Hacl.Impl.K256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ecdsa_verify_cmpr: r:QA.qelem -> pk:point -> u1:QA.qelem -> u2:QA.qelem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ QA.qas_nat h u1 < S.q /\ QA.qas_nat h u2 < S.q /\
0 < QA.qas_nat h r /\ QA.qas_nat h r < S.q)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk) in
b <==> (if S.is_proj_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r))) | [] | Hacl.Impl.K256.Verify.ecdsa_verify_cmpr | {
"file_name": "code/k256/Hacl.Impl.K256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
r: Hacl.K256.Scalar.qelem ->
pk: Hacl.Impl.K256.Point.point ->
u1: Hacl.K256.Scalar.qelem ->
u2: Hacl.K256.Scalar.qelem
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 3,
"end_line": 164,
"start_col": 2,
"start_line": 147
} |
FStar.HyperStack.ST.Stack | val ecdsa_verify_avoid_finv: p:point -> r:QA.qelem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ QA.qe_lt_q h r /\ 0 < QA.qas_nat h r /\
not (S.is_proj_point_at_inf (point_eval h p)))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = point_eval h0 p in
b <==> (S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r))) | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52.Lemmas",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.K256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.K256.Scalar",
"short_module": "QA"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "KL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ecdsa_verify_avoid_finv p r =
let h0 = ST.get () in
let x, y, z = getx p, gety p, getz p in
push_frame ();
let r_bytes = create 32ul (u8 0) in
let r_fe = create_felem () in
let tmp_q = create_felem () in
let tmp_x = create_felem () in
QA.store_qelem r_bytes r;
load_felem r_fe r_bytes;
let h1 = ST.get () in
//assert (inv_fully_reduced h1 r_fe);
//assert (as_nat h1 r_fe == qas_nat h1 r);
let h2 = ST.get () in
fnormalize tmp_x x;
let h3 = ST.get () in
BL.normalize5_lemma (1,1,1,1,2) (as_felem5 h2 x);
//assert (inv_fully_reduced h3 tmp_x);
//assert (inv_lazy_reduced2 h3 z);
let is_rz_x = fmul_eq_vartime r_fe z tmp_x in
//assert (is_rz_x == (S.fmul (as_nat h3 r_fe) (feval h3 z) = as_nat h3 tmp_x));
let res : bool =
if not is_rz_x then begin
let is_r_lt_p_m_q = is_felem_lt_prime_minus_order_vartime r_fe in
if is_r_lt_p_m_q then begin
assert (as_nat h1 r_fe < S.prime - S.q);
make_u52_5 tmp_q (make_order_k256 ());
let h4 = ST.get () in
BL.add5_lemma (1,1,1,1,1) (1,1,1,1,1) (as_felem5 h4 r_fe) (as_felem5 h4 tmp_q);
fadd tmp_q r_fe tmp_q;
fmul_eq_vartime tmp_q z tmp_x end
//assert (is_rqz_x == (S.fmul (feval h5 tmp) (feval h5 z) = as_nat h5 tmp_x));
else false end
else true in
pop_frame ();
KL.ecdsa_verify_avoid_finv (point_eval h0 p) (QA.qas_nat h0 r);
assert (res <==> (S.fmul (feval h0 x) (S.finv (feval h0 z)) % S.q = QA.qas_nat h0 r));
let h5 = ST.get () in
assert (modifies0 h0 h5);
res | val ecdsa_verify_avoid_finv: p:point -> r:QA.qelem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ QA.qe_lt_q h r /\ 0 < QA.qas_nat h r /\
not (S.is_proj_point_at_inf (point_eval h p)))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = point_eval h0 p in
b <==> (S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r)))
let ecdsa_verify_avoid_finv p r = | true | null | false | let h0 = ST.get () in
let x, y, z = getx p, gety p, getz p in
push_frame ();
let r_bytes = create 32ul (u8 0) in
let r_fe = create_felem () in
let tmp_q = create_felem () in
let tmp_x = create_felem () in
QA.store_qelem r_bytes r;
load_felem r_fe r_bytes;
let h1 = ST.get () in
let h2 = ST.get () in
fnormalize tmp_x x;
let h3 = ST.get () in
BL.normalize5_lemma (1, 1, 1, 1, 2) (as_felem5 h2 x);
let is_rz_x = fmul_eq_vartime r_fe z tmp_x in
let res:bool =
if not is_rz_x
then
let is_r_lt_p_m_q = is_felem_lt_prime_minus_order_vartime r_fe in
if is_r_lt_p_m_q
then
(assert (as_nat h1 r_fe < S.prime - S.q);
make_u52_5 tmp_q (make_order_k256 ());
let h4 = ST.get () in
BL.add5_lemma (1, 1, 1, 1, 1) (1, 1, 1, 1, 1) (as_felem5 h4 r_fe) (as_felem5 h4 tmp_q);
fadd tmp_q r_fe tmp_q;
fmul_eq_vartime tmp_q z tmp_x)
else false
else true
in
pop_frame ();
KL.ecdsa_verify_avoid_finv (point_eval h0 p) (QA.qas_nat h0 r);
assert (res <==> (S.fmul (feval h0 x) (S.finv (feval h0 z)) % S.q = QA.qas_nat h0 r));
let h5 = ST.get () in
assert (modifies0 h0 h5);
res | {
"checked_file": "Hacl.Impl.K256.Verify.fst.checked",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Lemmas.fsti.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Qinv.fst.checked",
"Hacl.Impl.K256.PointMul.fsti.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"Hacl.Impl.K256.GLV.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.K256.Verify.fst"
} | [] | [
"Hacl.Impl.K256.Point.point",
"Hacl.K256.Scalar.qelem",
"Hacl.K256.Field.felem",
"Prims.unit",
"Prims._assert",
"Lib.Buffer.modifies0",
"Prims.bool",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.l_iff",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Spec.K256.PointOps.fmul",
"Hacl.K256.Field.feval",
"Spec.K256.PointOps.finv",
"Spec.K256.PointOps.q",
"Hacl.K256.Scalar.qas_nat",
"Spec.K256.Lemmas.ecdsa_verify_avoid_finv",
"Hacl.Impl.K256.Point.point_eval",
"FStar.HyperStack.ST.pop_frame",
"Prims.op_Negation",
"Hacl.Impl.K256.Verify.fmul_eq_vartime",
"Hacl.K256.Field.fadd",
"Hacl.Spec.K256.Field52.Lemmas.add5_lemma",
"FStar.Pervasives.Native.Mktuple5",
"Prims.nat",
"Hacl.K256.Field.as_felem5",
"Hacl.K256.Field.make_u52_5",
"Hacl.K256.Field.make_order_k256",
"Prims.op_LessThan",
"Hacl.K256.Field.as_nat",
"Prims.op_Subtraction",
"Spec.K256.PointOps.prime",
"Hacl.K256.Field.is_felem_lt_prime_minus_order_vartime",
"Hacl.Spec.K256.Field52.Lemmas.normalize5_lemma",
"Hacl.K256.Field.fnormalize",
"Hacl.K256.Field.load_felem",
"Hacl.K256.Scalar.store_qelem",
"Hacl.K256.Field.create_felem",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.u8",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Hacl.Impl.K256.Point.getz",
"Hacl.Impl.K256.Point.gety",
"Hacl.Impl.K256.Point.getx"
] | [] | module Hacl.Impl.K256.Verify
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module KL = Spec.K256.Lemmas
open Hacl.K256.Field
open Hacl.Impl.K256.Point
open Hacl.Impl.K256.PointMul
open Hacl.Impl.K256.GLV
module QA = Hacl.K256.Scalar
module QI = Hacl.Impl.K256.Qinv
module BL = Hacl.Spec.K256.Field52.Lemmas
module BSeq = Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
inline_for_extraction noextract
val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q))
let ecdsa_verify_get_u12 u1 u2 r s z =
push_frame ();
let sinv = QA.create_qelem () in
QI.qinv sinv s;
QA.qmul u1 z sinv;
QA.qmul u2 r sinv;
pop_frame ()
val fmul_eq_vartime (r z x: felem) : Stack bool
(requires fun h ->
live h r /\ live h z /\ live h x /\ eq_or_disjoint r z /\
felem_fits5 (as_felem5 h r) (2,2,2,2,2) /\ as_nat h r < S.prime /\
inv_lazy_reduced2 h z /\ inv_fully_reduced h x)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == (S.fmul (as_nat h0 r) (feval h0 z) = as_nat h0 x))
[@CInline]
let fmul_eq_vartime r z x =
push_frame ();
let tmp = create_felem () in
fmul tmp r z;
let h1 = ST.get () in
fnormalize tmp tmp;
let h2 = ST.get () in
BL.normalize5_lemma (1,1,1,1,2) (as_felem5 h1 tmp);
assert (inv_fully_reduced h2 tmp);
let b = is_felem_eq_vartime tmp x in
pop_frame ();
b
inline_for_extraction noextract
val ecdsa_verify_avoid_finv: p:point -> r:QA.qelem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ QA.qe_lt_q h r /\ 0 < QA.qas_nat h r /\
not (S.is_proj_point_at_inf (point_eval h p)))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = point_eval h0 p in
b <==> (S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r))) | false | false | Hacl.Impl.K256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ecdsa_verify_avoid_finv: p:point -> r:QA.qelem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ QA.qe_lt_q h r /\ 0 < QA.qas_nat h r /\
not (S.is_proj_point_at_inf (point_eval h p)))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = point_eval h0 p in
b <==> (S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r))) | [] | Hacl.Impl.K256.Verify.ecdsa_verify_avoid_finv | {
"file_name": "code/k256/Hacl.Impl.K256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | p: Hacl.Impl.K256.Point.point -> r: Hacl.K256.Scalar.qelem -> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 5,
"end_line": 129,
"start_col": 33,
"start_line": 84
} |
FStar.HyperStack.ST.Stack | val ecdsa_verify_hashed_msg (msgHash:lbytes 32ul)
(public_key signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h msgHash /\ live h public_key /\ live h signature)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == S.ecdsa_verify_hashed_msg (as_seq h0 msgHash) (as_seq h0 public_key) (as_seq h0 signature)) | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52.Lemmas",
"short_module": "BL"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.K256.Qinv",
"short_module": "QI"
},
{
"abbrev": true,
"full_module": "Hacl.K256.Scalar",
"short_module": "QA"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.GLV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.PointMul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256.Point",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256.Field",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256.Lemmas",
"short_module": "KL"
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ecdsa_verify_hashed_msg msgHash public_key signature =
push_frame ();
let tmp = create 35ul (u64 0) in
let pk = sub tmp 0ul 15ul in
let r_q = sub tmp 15ul 4ul in
let s_q = sub tmp 19ul 4ul in
let u1 = sub tmp 23ul 4ul in
let u2 = sub tmp 27ul 4ul in
let m_q = sub tmp 31ul 4ul in
let is_pk_valid = load_point_vartime pk public_key in
let is_rs_valid = load_signature r_q s_q signature in
QA.load_qelem_modq m_q msgHash;
let res =
if not (is_pk_valid && is_rs_valid) then false
else begin
ecdsa_verify_get_u12 u1 u2 r_q s_q m_q;
ecdsa_verify_cmpr r_q pk u1 u2 end in
pop_frame ();
res | val ecdsa_verify_hashed_msg (msgHash:lbytes 32ul)
(public_key signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h msgHash /\ live h public_key /\ live h signature)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == S.ecdsa_verify_hashed_msg (as_seq h0 msgHash) (as_seq h0 public_key) (as_seq h0 signature))
let ecdsa_verify_hashed_msg msgHash public_key signature = | true | null | false | push_frame ();
let tmp = create 35ul (u64 0) in
let pk = sub tmp 0ul 15ul in
let r_q = sub tmp 15ul 4ul in
let s_q = sub tmp 19ul 4ul in
let u1 = sub tmp 23ul 4ul in
let u2 = sub tmp 27ul 4ul in
let m_q = sub tmp 31ul 4ul in
let is_pk_valid = load_point_vartime pk public_key in
let is_rs_valid = load_signature r_q s_q signature in
QA.load_qelem_modq m_q msgHash;
let res =
if not (is_pk_valid && is_rs_valid)
then false
else
(ecdsa_verify_get_u12 u1 u2 r_q s_q m_q;
ecdsa_verify_cmpr r_q pk u1 u2)
in
pop_frame ();
res | {
"checked_file": "Hacl.Impl.K256.Verify.fst.checked",
"dependencies": [
"Spec.K256.Lemmas.fsti.checked",
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Lemmas.fsti.checked",
"Hacl.K256.Scalar.fsti.checked",
"Hacl.K256.Field.fsti.checked",
"Hacl.Impl.K256.Qinv.fst.checked",
"Hacl.Impl.K256.PointMul.fsti.checked",
"Hacl.Impl.K256.Point.fsti.checked",
"Hacl.Impl.K256.GLV.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.K256.Verify.fst"
} | [] | [
"Hacl.Impl.K256.Verify.lbytes",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Prims.op_Negation",
"Prims.op_AmpAmp",
"Hacl.Impl.K256.Verify.ecdsa_verify_cmpr",
"Hacl.Impl.K256.Verify.ecdsa_verify_get_u12",
"Hacl.K256.Scalar.load_qelem_modq",
"Hacl.Impl.K256.Verify.load_signature",
"Hacl.Impl.K256.Point.load_point_vartime",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"Lib.IntTypes.uint64",
"Lib.Buffer.create",
"Lib.IntTypes.u64",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.K256.Verify
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module S = Spec.K256
module KL = Spec.K256.Lemmas
open Hacl.K256.Field
open Hacl.Impl.K256.Point
open Hacl.Impl.K256.PointMul
open Hacl.Impl.K256.GLV
module QA = Hacl.K256.Scalar
module QI = Hacl.Impl.K256.Qinv
module BL = Hacl.Spec.K256.Field52.Lemmas
module BSeq = Lib.ByteSequence
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let lbytes len = lbuffer uint8 len
inline_for_extraction noextract
val ecdsa_verify_get_u12 (u1 u2 r s z: QA.qelem) : Stack unit
(requires fun h ->
live h r /\ live h s /\ live h z /\ live h u1 /\ live h u2 /\
disjoint u1 u2 /\ disjoint u1 z /\ disjoint u1 r /\ disjoint u1 s /\
disjoint u2 z /\ disjoint u2 r /\ disjoint u2 s /\
QA.qas_nat h s < S.q /\ QA.qas_nat h z < S.q /\ QA.qas_nat h r < S.q)
(ensures fun h0 _ h1 -> modifies (loc u1 |+| loc u2) h0 h1 /\
(let sinv = S.qinv (QA.qas_nat h0 s) in
QA.qas_nat h1 u1 == QA.qas_nat h0 z * sinv % S.q /\
QA.qas_nat h1 u2 == QA.qas_nat h0 r * sinv % S.q))
let ecdsa_verify_get_u12 u1 u2 r s z =
push_frame ();
let sinv = QA.create_qelem () in
QI.qinv sinv s;
QA.qmul u1 z sinv;
QA.qmul u2 r sinv;
pop_frame ()
val fmul_eq_vartime (r z x: felem) : Stack bool
(requires fun h ->
live h r /\ live h z /\ live h x /\ eq_or_disjoint r z /\
felem_fits5 (as_felem5 h r) (2,2,2,2,2) /\ as_nat h r < S.prime /\
inv_lazy_reduced2 h z /\ inv_fully_reduced h x)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == (S.fmul (as_nat h0 r) (feval h0 z) = as_nat h0 x))
[@CInline]
let fmul_eq_vartime r z x =
push_frame ();
let tmp = create_felem () in
fmul tmp r z;
let h1 = ST.get () in
fnormalize tmp tmp;
let h2 = ST.get () in
BL.normalize5_lemma (1,1,1,1,2) (as_felem5 h1 tmp);
assert (inv_fully_reduced h2 tmp);
let b = is_felem_eq_vartime tmp x in
pop_frame ();
b
inline_for_extraction noextract
val ecdsa_verify_avoid_finv: p:point -> r:QA.qelem -> Stack bool
(requires fun h ->
live h p /\ live h r /\ disjoint p r /\
point_inv h p /\ QA.qe_lt_q h r /\ 0 < QA.qas_nat h r /\
not (S.is_proj_point_at_inf (point_eval h p)))
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let (_X, _Y, _Z) = point_eval h0 p in
b <==> (S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r)))
let ecdsa_verify_avoid_finv p r =
let h0 = ST.get () in
let x, y, z = getx p, gety p, getz p in
push_frame ();
let r_bytes = create 32ul (u8 0) in
let r_fe = create_felem () in
let tmp_q = create_felem () in
let tmp_x = create_felem () in
QA.store_qelem r_bytes r;
load_felem r_fe r_bytes;
let h1 = ST.get () in
//assert (inv_fully_reduced h1 r_fe);
//assert (as_nat h1 r_fe == qas_nat h1 r);
let h2 = ST.get () in
fnormalize tmp_x x;
let h3 = ST.get () in
BL.normalize5_lemma (1,1,1,1,2) (as_felem5 h2 x);
//assert (inv_fully_reduced h3 tmp_x);
//assert (inv_lazy_reduced2 h3 z);
let is_rz_x = fmul_eq_vartime r_fe z tmp_x in
//assert (is_rz_x == (S.fmul (as_nat h3 r_fe) (feval h3 z) = as_nat h3 tmp_x));
let res : bool =
if not is_rz_x then begin
let is_r_lt_p_m_q = is_felem_lt_prime_minus_order_vartime r_fe in
if is_r_lt_p_m_q then begin
assert (as_nat h1 r_fe < S.prime - S.q);
make_u52_5 tmp_q (make_order_k256 ());
let h4 = ST.get () in
BL.add5_lemma (1,1,1,1,1) (1,1,1,1,1) (as_felem5 h4 r_fe) (as_felem5 h4 tmp_q);
fadd tmp_q r_fe tmp_q;
fmul_eq_vartime tmp_q z tmp_x end
//assert (is_rqz_x == (S.fmul (feval h5 tmp) (feval h5 z) = as_nat h5 tmp_x));
else false end
else true in
pop_frame ();
KL.ecdsa_verify_avoid_finv (point_eval h0 p) (QA.qas_nat h0 r);
assert (res <==> (S.fmul (feval h0 x) (S.finv (feval h0 z)) % S.q = QA.qas_nat h0 r));
let h5 = ST.get () in
assert (modifies0 h0 h5);
res
inline_for_extraction noextract
val ecdsa_verify_cmpr: r:QA.qelem -> pk:point -> u1:QA.qelem -> u2:QA.qelem -> Stack bool
(requires fun h ->
live h r /\ live h pk /\ live h u1 /\ live h u2 /\
disjoint r u1 /\ disjoint r u2 /\ disjoint r pk /\
disjoint pk u1 /\ disjoint pk u2 /\
point_inv h pk /\ QA.qas_nat h u1 < S.q /\ QA.qas_nat h u2 < S.q /\
0 < QA.qas_nat h r /\ QA.qas_nat h r < S.q)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(let _X, _Y, _Z = S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk) in
b <==> (if S.is_proj_point_at_inf (_X, _Y, _Z) then false
else S.fmul _X (S.finv _Z) % S.q = QA.qas_nat h0 r)))
let ecdsa_verify_cmpr r pk u1 u2 =
push_frame ();
let res = create_point () in
let h0 = ST.get () in
point_mul_g_double_split_lambda_vartime res u1 u2 pk;
let h1 = ST.get () in
assert (S.to_aff_point (point_eval h1 res) ==
S.to_aff_point (S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk)));
KL.lemma_aff_is_point_at_inf (point_eval h1 res);
KL.lemma_aff_is_point_at_inf (S.point_mul_double_g (QA.qas_nat h0 u1) (QA.qas_nat h0 u2)
(point_eval h0 pk));
let b =
if is_proj_point_at_inf_vartime res then false
else ecdsa_verify_avoid_finv res r in
pop_frame ();
b
inline_for_extraction noextract
val load_signature (r_q s_q:QA.qelem) (signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h signature /\ live h r_q /\ live h s_q /\
disjoint r_q s_q /\ disjoint r_q signature /\ disjoint s_q signature)
(ensures fun h0 res h1 -> modifies (loc r_q |+| loc s_q) h0 h1 /\
(let sign_r = gsub signature 0ul 32ul in
let sign_s = gsub signature 32ul 32ul in
let r_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_r) in
let s_q_nat = BSeq.nat_from_bytes_be (as_seq h0 sign_s) in
QA.qas_nat h1 r_q = r_q_nat /\ QA.qas_nat h1 s_q = s_q_nat /\
res == (0 < r_q_nat && r_q_nat < S.q && 0 < s_q_nat && s_q_nat < S.q)))
let load_signature r_q s_q signature =
let is_r_valid = QA.load_qelem_vartime r_q (sub signature 0ul 32ul) in
let is_s_valid = QA.load_qelem_vartime s_q (sub signature 32ul 32ul) in
is_r_valid && is_s_valid
inline_for_extraction noextract
val ecdsa_verify_hashed_msg (msgHash:lbytes 32ul)
(public_key signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h msgHash /\ live h public_key /\ live h signature)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == S.ecdsa_verify_hashed_msg (as_seq h0 msgHash) (as_seq h0 public_key) (as_seq h0 signature)) | false | false | Hacl.Impl.K256.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ecdsa_verify_hashed_msg (msgHash:lbytes 32ul)
(public_key signature:lbytes 64ul) : Stack bool
(requires fun h ->
live h msgHash /\ live h public_key /\ live h signature)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
b == S.ecdsa_verify_hashed_msg (as_seq h0 msgHash) (as_seq h0 public_key) (as_seq h0 signature)) | [] | Hacl.Impl.K256.Verify.ecdsa_verify_hashed_msg | {
"file_name": "code/k256/Hacl.Impl.K256.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
msgHash: Hacl.Impl.K256.Verify.lbytes 32ul ->
public_key: Hacl.Impl.K256.Verify.lbytes 64ul ->
signature: Hacl.Impl.K256.Verify.lbytes 64ul
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 5,
"end_line": 214,
"start_col": 2,
"start_line": 195
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Galois",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Math.Poly2_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Spec.GaloisField",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "Lib.IntTypes",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Galois",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Galois",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fmul (#f:G.field) (a b:G.felem f) = G.fmul #f a b | let fmul (#f: G.field) (a b: G.felem f) = | false | null | false | G.fmul #f a b | {
"checked_file": "Vale.Math.Poly2.Galois.Lemmas.fsti.checked",
"dependencies": [
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Galois.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2.Galois.Lemmas.fsti"
} | [
"total"
] | [
"Spec.GaloisField.field",
"Spec.GaloisField.felem",
"Spec.GaloisField.fmul"
] | [] | module Vale.Math.Poly2.Galois.Lemmas
open FStar.Mul
module I = Lib.IntTypes
module G = Spec.GaloisField
module P = Vale.Math.Poly2_s
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Galois | false | false | Vale.Math.Poly2.Galois.Lemmas.fsti | {
"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"
} | null | val fmul : a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> Spec.GaloisField.felem f | [] | Vale.Math.Poly2.Galois.Lemmas.fmul | {
"file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.Lemmas.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> Spec.GaloisField.felem f | {
"end_col": 60,
"end_line": 11,
"start_col": 47,
"start_line": 11
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Galois",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2_s",
"short_module": null
},
{
"abbrev": true,
"full_module": "Vale.Math.Poly2_s",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Spec.GaloisField",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "Lib.IntTypes",
"short_module": "I"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Galois",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Math.Poly2.Galois",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fadd (#f:G.field) (a b:G.felem f) = G.fadd #f a b | let fadd (#f: G.field) (a b: G.felem f) = | false | null | false | G.fadd #f a b | {
"checked_file": "Vale.Math.Poly2.Galois.Lemmas.fsti.checked",
"dependencies": [
"Vale.Math.Poly2_s.fsti.checked",
"Vale.Math.Poly2.Galois.fsti.checked",
"Vale.Math.Poly2.fsti.checked",
"Spec.GaloisField.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Math.Poly2.Galois.Lemmas.fsti"
} | [
"total"
] | [
"Spec.GaloisField.field",
"Spec.GaloisField.felem",
"Spec.GaloisField.fadd"
] | [] | module Vale.Math.Poly2.Galois.Lemmas
open FStar.Mul
module I = Lib.IntTypes
module G = Spec.GaloisField
module P = Vale.Math.Poly2_s
open Vale.Math.Poly2_s
open Vale.Math.Poly2
open Vale.Math.Poly2.Galois | false | false | Vale.Math.Poly2.Galois.Lemmas.fsti | {
"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"
} | null | val fadd : a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> Spec.GaloisField.felem f | [] | Vale.Math.Poly2.Galois.Lemmas.fadd | {
"file_name": "vale/code/lib/math/Vale.Math.Poly2.Galois.Lemmas.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.GaloisField.felem f -> b: Spec.GaloisField.felem f -> Spec.GaloisField.felem f | {
"end_col": 60,
"end_line": 10,
"start_col": 47,
"start_line": 10
} |
|
Prims.Pure | val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n)
(requires (b2t (a < max_int n)))
(ensures (fun b -> a + 1 = b)) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let incr_underspec #n a =
if a < max_int n then a + 1 else 0 | val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n)
(requires (b2t (a < max_int n)))
(ensures (fun b -> a + 1 = b))
let incr_underspec #n a = | false | null | false | if a < max_int n then a + 1 else 0 | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [] | [
"Prims.pos",
"FStar.Int.int_t",
"Prims.op_LessThan",
"FStar.Int.max_int",
"Prims.op_Addition",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> () | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val incr_underspec: #n:pos -> a:int_t n -> Pure (int_t n)
(requires (b2t (a < max_int n)))
(ensures (fun b -> a + 1 = b)) | [] | FStar.Int.incr_underspec | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> Prims.Pure (FStar.Int.int_t n) | {
"end_col": 36,
"end_line": 38,
"start_col": 2,
"start_line": 38
} |
FStar.Pervasives.Lemma | val logand_pos_le: #n:pos{1 < n} -> a:int_t n{0 <= a} -> b:int_t n{0 <= b} ->
Lemma (0 <= logand a b /\ logand a b <= a /\ logand a b <= b) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b) | val logand_pos_le: #n:pos{1 < n} -> a:int_t n{0 <= a} -> b:int_t n{0 <= b} ->
Lemma (0 <= logand a b /\ logand a b <= a /\ logand a b <= b)
let logand_pos_le #n a b = | false | null | true | UInt.logand_le (to_uint a) (to_uint b) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.int_t",
"Prims.op_LessThanOrEqual",
"FStar.UInt.logand_le",
"FStar.Int.to_uint",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a
let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1 | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logand_pos_le: #n:pos{1 < n} -> a:int_t n{0 <= a} -> b:int_t n{0 <= b} ->
Lemma (0 <= logand a b /\ logand a b <= a /\ logand a b <= b) | [] | FStar.Int.logand_pos_le | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n {0 <= a} -> b: FStar.Int.int_t n {0 <= b}
-> FStar.Pervasives.Lemma
(ensures 0 <= FStar.Int.logand a b /\ FStar.Int.logand a b <= a /\ FStar.Int.logand a b <= b) | {
"end_col": 40,
"end_line": 143,
"start_col": 2,
"start_line": 143
} |
Prims.Pure | val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n)
(requires (b2t (a > min_int n)))
(ensures (fun b -> a - 1 = b)) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let decr_underspec #n a =
if a > min_int n then a - 1 else 0 | val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n)
(requires (b2t (a > min_int n)))
(ensures (fun b -> a - 1 = b))
let decr_underspec #n a = | false | null | false | if a > min_int n then a - 1 else 0 | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [] | [
"Prims.pos",
"FStar.Int.int_t",
"Prims.op_GreaterThan",
"FStar.Int.min_int",
"Prims.op_Subtraction",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0 | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val decr_underspec: #n:pos -> a:int_t n -> Pure (int_t n)
(requires (b2t (a > min_int n)))
(ensures (fun b -> a - 1 = b)) | [] | FStar.Int.decr_underspec | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> Prims.Pure (FStar.Int.int_t n) | {
"end_col": 36,
"end_line": 41,
"start_col": 2,
"start_line": 41
} |
Prims.Pure | val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a * b) n ==> a * b = c)) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let mul_underspec #n a b =
if fits (a*b) n then a * b else 0 | val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a * b) n ==> a * b = c))
let mul_underspec #n a b = | false | null | false | if fits (a * b) n then a * b else 0 | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.fits",
"FStar.Mul.op_Star",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0 | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val mul_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a * b) n ==> a * b = c)) | [] | FStar.Int.mul_underspec | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> Prims.Pure (FStar.Int.int_t n) | {
"end_col": 35,
"end_line": 50,
"start_col": 2,
"start_line": 50
} |
Prims.Pure | val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a + b) n ==> a + b = c)) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let add_underspec #n a b =
if fits (a+b) n then a + b else 0 | val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a + b) n ==> a + b = c))
let add_underspec #n a b = | false | null | false | if fits (a + b) n then a + b else 0 | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.fits",
"Prims.op_Addition",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0 | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val add_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a + b) n ==> a + b = c)) | [] | FStar.Int.add_underspec | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> Prims.Pure (FStar.Int.int_t n) | {
"end_col": 35,
"end_line": 44,
"start_col": 2,
"start_line": 44
} |
FStar.Pervasives.Lemma | val pow2_values: x:nat -> Lemma
(let p = pow2 x in
match x with
| 0 -> p=1
| 1 -> p=2
| 8 -> p=256
| 16 -> p=65536
| 31 -> p=2147483648
| 32 -> p=4294967296
| 63 -> p=9223372036854775808
| 64 -> p=18446744073709551616
| _ -> True)
[SMTPat (pow2 x)] | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> () | val pow2_values: x:nat -> Lemma
(let p = pow2 x in
match x with
| 0 -> p=1
| 1 -> p=2
| 8 -> p=256
| 16 -> p=65536
| 31 -> p=2147483648
| 32 -> p=4294967296
| 63 -> p=9223372036854775808
| 64 -> p=18446744073709551616
| _ -> True)
[SMTPat (pow2 x)]
let pow2_values x = | false | null | true | match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> () | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.nat",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"Prims.pow2",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pow2_values: x:nat -> Lemma
(let p = pow2 x in
match x with
| 0 -> p=1
| 1 -> p=2
| 8 -> p=256
| 16 -> p=65536
| 31 -> p=2147483648
| 32 -> p=4294967296
| 63 -> p=9223372036854775808
| 64 -> p=18446744073709551616
| _ -> True)
[SMTPat (pow2 x)] | [] | FStar.Int.pow2_values | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | x: Prims.nat
-> FStar.Pervasives.Lemma
(ensures
(let p = Prims.pow2 x in
(match x with
| 0 -> p = 1
| 1 -> p = 2
| 8 -> p = 256
| 16 -> p = 65536
| 31 -> p = 2147483648
| 32 -> p = 4294967296
| 63 -> p = 9223372036854775808
| 64 -> p = 18446744073709551616
| _ -> Prims.l_True)
<:
Type0)) [SMTPat (Prims.pow2 x)] | {
"end_col": 13,
"end_line": 35,
"start_col": 3,
"start_line": 26
} |
FStar.Pervasives.Lemma | val lognot_negative: #n:pos -> a:int_t n -> Lemma
(requires a < 0)
(ensures lognot a == UInt.lognot #n (a + pow2 n)) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lognot_negative #n a =
assert_norm (pow2 n = 2 * pow2 (n - 1));
UInt.lemma_lognot_value_mod #n (a + pow2 n) | val lognot_negative: #n:pos -> a:int_t n -> Lemma
(requires a < 0)
(ensures lognot a == UInt.lognot #n (a + pow2 n))
let lognot_negative #n a = | false | null | true | assert_norm (pow2 n = 2 * pow2 (n - 1));
UInt.lemma_lognot_value_mod #n (a + pow2 n) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.UInt.lemma_lognot_value_mod",
"Prims.op_Addition",
"Prims.pow2",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Mul.op_Star",
"Prims.op_Subtraction"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a
let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let logxor_inv #n a b =
UInt.logxor_inv (to_uint a) (to_uint b)
let logxor_neq_nonzero #n a b =
UInt.logxor_neq_nonzero (to_uint a) (to_uint b) | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lognot_negative: #n:pos -> a:int_t n -> Lemma
(requires a < 0)
(ensures lognot a == UInt.lognot #n (a + pow2 n)) | [] | FStar.Int.lognot_negative | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n
-> FStar.Pervasives.Lemma (requires a < 0)
(ensures FStar.Int.lognot a == FStar.UInt.lognot (a + Prims.pow2 n)) | {
"end_col": 45,
"end_line": 173,
"start_col": 2,
"start_line": 172
} |
FStar.Pervasives.Lemma | val logand_commutative: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires True) (ensures (logand #n a b = logand #n b a)) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a) | val logand_commutative: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires True) (ensures (logand #n a b = logand #n b a))
let logand_commutative #n a b = | false | null | true | nth_lemma #n (logand #n a b) (logand #n b a) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logand",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = () | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logand_commutative: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires True) (ensures (logand #n a b = logand #n b a)) | [] | FStar.Int.logand_commutative | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> b: FStar.Int.int_t n
-> FStar.Pervasives.Lemma (ensures FStar.Int.logand a b = FStar.Int.logand b a) | {
"end_col": 76,
"end_line": 123,
"start_col": 32,
"start_line": 123
} |
FStar.Pervasives.Lemma | val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n ->
Lemma (requires from_vec a = from_vec b) (ensures equal a b) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b | val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n ->
Lemma (requires from_vec a = from_vec b) (ensures equal a b)
let from_vec_lemma_2 #n a b = | false | null | true | inverse_vec_lemma a;
inverse_vec_lemma b | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.BitVector.bv_t",
"FStar.Int.inverse_vec_lemma",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = () | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val from_vec_lemma_2: #n:pos -> a:bv_t n -> b:bv_t n ->
Lemma (requires from_vec a = from_vec b) (ensures equal a b) | [] | FStar.Int.from_vec_lemma_2 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.BitVector.bv_t n -> b: FStar.BitVector.bv_t n
-> FStar.Pervasives.Lemma (requires FStar.Int.from_vec a = FStar.Int.from_vec b)
(ensures FStar.Seq.Base.equal a b) | {
"end_col": 70,
"end_line": 80,
"start_col": 30,
"start_line": 80
} |
FStar.Pervasives.Lemma | val logand_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n ->
Lemma (logand #n (logand #n a b) c = logand #n a (logand #n b c)) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c)) | val logand_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n ->
Lemma (logand #n (logand #n a b) c = logand #n a (logand #n b c))
let logand_associative #n a b c = | false | null | true | nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c)) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logand",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a) | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logand_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n ->
Lemma (logand #n (logand #n a b) c = logand #n a (logand #n b c)) | [] | FStar.Int.logand_associative | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> c: FStar.Int.int_t n
-> FStar.Pervasives.Lemma
(ensures FStar.Int.logand (FStar.Int.logand a b) c = FStar.Int.logand a (FStar.Int.logand b c)) | {
"end_col": 74,
"end_line": 126,
"start_col": 2,
"start_line": 126
} |
Prims.Pure | val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n)
(requires True)
(ensures (fun c ->
(b <> 0 /\ size (a / b) n) ==> a / b = c)) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let div_underspec #n a b =
if fits (a / b) n then a / b else 0 | val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n)
(requires True)
(ensures (fun c ->
(b <> 0 /\ size (a / b) n) ==> a / b = c))
let div_underspec #n a b = | false | null | false | if fits (a / b) n then a / b else 0 | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [] | [
"Prims.pos",
"FStar.Int.int_t",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.int",
"FStar.Int.fits",
"FStar.Int.op_Slash",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0 | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val div_underspec: #n:pos -> a:int_t n -> b:int_t n{b <> 0} -> Pure (int_t n)
(requires True)
(ensures (fun c ->
(b <> 0 /\ size (a / b) n) ==> a / b = c)) | [] | FStar.Int.div_underspec | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> b: FStar.Int.int_t n {b <> 0} -> Prims.Pure (FStar.Int.int_t n) | {
"end_col": 37,
"end_line": 53,
"start_col": 2,
"start_line": 53
} |
FStar.Pervasives.Lemma | val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b) | val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b)
let to_vec_lemma_2 #n a b = | false | null | true | UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.UInt.to_vec_lemma_2",
"FStar.Int.to_uint",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = () | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val to_vec_lemma_2: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires equal (to_vec a) (to_vec b)) (ensures a = b) | [] | FStar.Int.to_vec_lemma_2 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> b: FStar.Int.int_t n
-> FStar.Pervasives.Lemma
(requires FStar.Seq.Base.equal (FStar.Int.to_vec a) (FStar.Int.to_vec b)) (ensures a = b) | {
"end_col": 48,
"end_line": 65,
"start_col": 2,
"start_line": 65
} |
FStar.Pervasives.Lemma | val ones_from_vec_lemma: #n:pos ->
Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n)
[SMTPat (from_vec (ones_vec #n))] | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n) | val ones_from_vec_lemma: #n:pos ->
Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n)
[SMTPat (from_vec (ones_vec #n))]
let ones_from_vec_lemma #n = | false | null | true | to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.to_vec_lemma_2",
"FStar.Int.from_vec",
"FStar.BitVector.ones_vec",
"FStar.Int.ones",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = () | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ones_from_vec_lemma: #n:pos ->
Lemma (requires True) (ensures from_vec (ones_vec #n) = ones n)
[SMTPat (from_vec (ones_vec #n))] | [] | FStar.Int.ones_from_vec_lemma | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | FStar.Pervasives.Lemma (ensures FStar.Int.from_vec FStar.BitVector.ones_vec = FStar.Int.ones n)
[SMTPat (FStar.Int.from_vec FStar.BitVector.ones_vec)] | {
"end_col": 50,
"end_line": 103,
"start_col": 2,
"start_line": 103
} |
FStar.Pervasives.Lemma | val zero_from_vec_lemma: #n:pos ->
Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n)
[SMTPat (from_vec (zero_vec #n))] | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n) | val zero_from_vec_lemma: #n:pos ->
Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n)
[SMTPat (from_vec (zero_vec #n))]
let zero_from_vec_lemma #n = | false | null | true | to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.to_vec_lemma_2",
"FStar.Int.from_vec",
"FStar.BitVector.zero_vec",
"FStar.Int.zero",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val zero_from_vec_lemma: #n:pos ->
Lemma (requires True) (ensures from_vec (zero_vec #n) = zero n)
[SMTPat (from_vec (zero_vec #n))] | [] | FStar.Int.zero_from_vec_lemma | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | FStar.Pervasives.Lemma (ensures FStar.Int.from_vec FStar.BitVector.zero_vec = FStar.Int.zero n)
[SMTPat (FStar.Int.from_vec FStar.BitVector.zero_vec)] | {
"end_col": 77,
"end_line": 85,
"start_col": 29,
"start_line": 85
} |
FStar.Pervasives.Lemma | val pow2_from_vec_lemma: #n:pos -> p:pos{p < n-1} ->
Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1))
[SMTPat (from_vec (elem_vec #n p))] | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1)) | val pow2_from_vec_lemma: #n:pos -> p:pos{p < n-1} ->
Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1))
[SMTPat (from_vec (elem_vec #n p))]
let pow2_from_vec_lemma #n p = | false | null | true | to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1)) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"FStar.Int.to_vec_lemma_2",
"FStar.Int.from_vec",
"FStar.BitVector.elem_vec",
"FStar.Int.pow2_n",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pow2_from_vec_lemma: #n:pos -> p:pos{p < n-1} ->
Lemma (requires True) (ensures from_vec (elem_vec #n p) = pow2_n #n (n - p - 1))
[SMTPat (from_vec (elem_vec #n p))] | [] | FStar.Int.pow2_from_vec_lemma | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | p: Prims.pos{p < n - 1}
-> FStar.Pervasives.Lemma
(ensures FStar.Int.from_vec (FStar.BitVector.elem_vec p) = FStar.Int.pow2_n (n - p - 1))
[SMTPat (FStar.Int.from_vec (FStar.BitVector.elem_vec p))] | {
"end_col": 67,
"end_line": 98,
"start_col": 2,
"start_line": 98
} |
FStar.Pervasives.Lemma | val logand_self: #n:pos -> a:int_t n ->
Lemma (logand #n a a = a) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logand_self #n a = nth_lemma #n (logand #n a a) a | val logand_self: #n:pos -> a:int_t n ->
Lemma (logand #n a a = a)
let logand_self #n a = | false | null | true | nth_lemma #n (logand #n a a) a | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logand",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c)) | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logand_self: #n:pos -> a:int_t n ->
Lemma (logand #n a a = a) | [] | FStar.Int.logand_self | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> FStar.Pervasives.Lemma (ensures FStar.Int.logand a a = a) | {
"end_col": 53,
"end_line": 128,
"start_col": 23,
"start_line": 128
} |
FStar.Pervasives.Lemma | val nth_lemma: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires forall (i:nat{i < n}). nth a i = nth b i)
(ensures a = b) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b | val nth_lemma: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires forall (i:nat{i < n}). nth a i = nth b i)
(ensures a = b)
let nth_lemma #n a b = | false | null | true | assert (forall (i: nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.to_vec_lemma_2",
"Prims.unit",
"Prims._assert",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.bool",
"FStar.Seq.Base.index",
"FStar.Int.to_vec"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n) | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val nth_lemma: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires forall (i:nat{i < n}). nth a i = nth b i)
(ensures a = b) | [] | FStar.Int.nth_lemma | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> b: FStar.Int.int_t n
-> FStar.Pervasives.Lemma
(requires forall (i: Prims.nat{i < n}). FStar.Int.nth a i = FStar.Int.nth b i) (ensures a = b) | {
"end_col": 20,
"end_line": 107,
"start_col": 2,
"start_line": 106
} |
FStar.Pervasives.Lemma | val logxor_lemma_1: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logxor #n a (zero n) = a)) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a | val logxor_lemma_1: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logxor #n a (zero n) = a))
let logxor_lemma_1 #n a = | false | null | true | nth_lemma #n (logxor #n a (zero n)) a | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logxor",
"FStar.Int.zero",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a
let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n) | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logxor_lemma_1: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logxor #n a (zero n) = a)) | [] | FStar.Int.logxor_lemma_1 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> FStar.Pervasives.Lemma (ensures FStar.Int.logxor a (FStar.Int.zero n) = a) | {
"end_col": 63,
"end_line": 161,
"start_col": 26,
"start_line": 161
} |
FStar.Pervasives.Lemma | val logand_pow2_minus_one: #n:pos{1 < n} -> a:int_t n -> m:pos{m < n} ->
Lemma (0 <= logand a (pow2_minus_one m) /\
logand a (pow2_minus_one m) <= pow2_minus_one #n m) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m)) | val logand_pow2_minus_one: #n:pos{1 < n} -> a:int_t n -> m:pos{m < n} ->
Lemma (0 <= logand a (pow2_minus_one m) /\
logand a (pow2_minus_one m) <= pow2_minus_one #n m)
let logand_pow2_minus_one #n a m = | false | null | true | UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m)) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.int_t",
"FStar.UInt.logand_le",
"FStar.Int.to_uint",
"FStar.Int.pow2_minus_one",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a
let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b) | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logand_pow2_minus_one: #n:pos{1 < n} -> a:int_t n -> m:pos{m < n} ->
Lemma (0 <= logand a (pow2_minus_one m) /\
logand a (pow2_minus_one m) <= pow2_minus_one #n m) | [] | FStar.Int.logand_pow2_minus_one | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> m: Prims.pos{m < n}
-> FStar.Pervasives.Lemma
(ensures
0 <= FStar.Int.logand a (FStar.Int.pow2_minus_one m) /\
FStar.Int.logand a (FStar.Int.pow2_minus_one m) <= FStar.Int.pow2_minus_one m) | {
"end_col": 60,
"end_line": 146,
"start_col": 2,
"start_line": 146
} |
FStar.Pervasives.Lemma | val logxor_self: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logxor #n a a = zero n)) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n) | val logxor_self: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logxor #n a a = zero n))
let logxor_self #n a = | false | null | true | nth_lemma #n (logxor #n a a) (zero n) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logxor",
"FStar.Int.zero",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a
let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c)) | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logxor_self: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logxor #n a a = zero n)) | [] | FStar.Int.logxor_self | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> FStar.Pervasives.Lemma (ensures FStar.Int.logxor a a = FStar.Int.zero n) | {
"end_col": 60,
"end_line": 159,
"start_col": 23,
"start_line": 159
} |
FStar.Pervasives.Lemma | val logxor_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n ->
Lemma (requires True) (ensures (logxor #n (logxor #n a b) c = logxor #n a (logxor #n b c))) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c)) | val logxor_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n ->
Lemma (requires True) (ensures (logxor #n (logxor #n a b) c = logxor #n a (logxor #n b c)))
let logxor_associative #n a b c = | false | null | true | nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c)) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logxor",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a
let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a) | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logxor_associative: #n:pos -> a:int_t n -> b:int_t n -> c:int_t n ->
Lemma (requires True) (ensures (logxor #n (logxor #n a b) c = logxor #n a (logxor #n b c))) | [] | FStar.Int.logxor_associative | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> c: FStar.Int.int_t n
-> FStar.Pervasives.Lemma
(ensures FStar.Int.logxor (FStar.Int.logxor a b) c = FStar.Int.logxor a (FStar.Int.logxor b c)) | {
"end_col": 106,
"end_line": 157,
"start_col": 34,
"start_line": 157
} |
FStar.Pervasives.Lemma | val logxor_inv: #n:pos -> a:int_t n -> b:int_t n -> Lemma
(a = logxor #n (logxor #n a b) b) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logxor_inv #n a b =
UInt.logxor_inv (to_uint a) (to_uint b) | val logxor_inv: #n:pos -> a:int_t n -> b:int_t n -> Lemma
(a = logxor #n (logxor #n a b) b)
let logxor_inv #n a b = | false | null | true | UInt.logxor_inv (to_uint a) (to_uint b) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.UInt.logxor_inv",
"FStar.Int.to_uint",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a
let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a) | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logxor_inv: #n:pos -> a:int_t n -> b:int_t n -> Lemma
(a = logxor #n (logxor #n a b) b) | [] | FStar.Int.logxor_inv | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> b: FStar.Int.int_t n
-> FStar.Pervasives.Lemma (ensures a = FStar.Int.logxor (FStar.Int.logxor a b) b) | {
"end_col": 41,
"end_line": 166,
"start_col": 2,
"start_line": 166
} |
FStar.Pervasives.Lemma | val logand_lemma_2: #n:pos -> a:int_t n ->
Lemma (logand #n a (ones n) = a) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a | val logand_lemma_2: #n:pos -> a:int_t n ->
Lemma (logand #n a (ones n) = a)
let logand_lemma_2 #n a = | false | null | true | nth_lemma #n (logand #n a (ones n)) a | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logand",
"FStar.Int.ones",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n) | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logand_lemma_2: #n:pos -> a:int_t n ->
Lemma (logand #n a (ones n) = a) | [] | FStar.Int.logand_lemma_2 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> FStar.Pervasives.Lemma (ensures FStar.Int.logand a (FStar.Int.ones n) = a) | {
"end_col": 39,
"end_line": 134,
"start_col": 2,
"start_line": 134
} |
FStar.Pervasives.Lemma | val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} ->
Lemma (requires (size a n)) (ensures (size (a / b) n)) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b) | val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} ->
Lemma (requires (size a n)) (ensures (size (a / b) n))
let div_size #n a b = | false | null | true | FStar.Math.Lib.slash_decr_axiom (abs a) (abs b) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.min_int",
"Prims.op_disEquality",
"Prims.int",
"FStar.Math.Lib.slash_decr_axiom",
"Prims.abs",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0 | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val div_size: #n:pos -> a:int_t n{min_int n < a} -> b:int_t n{b <> 0} ->
Lemma (requires (size a n)) (ensures (size (a / b) n)) | [] | FStar.Int.div_size | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n {FStar.Int.min_int n < a} -> b: FStar.Int.int_t n {b <> 0}
-> FStar.Pervasives.Lemma (requires FStar.Int.size a n) (ensures FStar.Int.size (a / b) n) | {
"end_col": 49,
"end_line": 56,
"start_col": 2,
"start_line": 56
} |
FStar.Pervasives.Lemma | val logxor_lemma_2: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logxor #n a (ones n) = lognot #n a)) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a) | val logxor_lemma_2: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logxor #n a (ones n) = lognot #n a))
let logxor_lemma_2 #n a = | false | null | true | nth_lemma #n (logxor #n a (ones n)) (lognot #n a) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logxor",
"FStar.Int.ones",
"FStar.Int.lognot",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a
let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logxor_lemma_2: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logxor #n a (ones n) = lognot #n a)) | [] | FStar.Int.logxor_lemma_2 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n
-> FStar.Pervasives.Lemma (ensures FStar.Int.logxor a (FStar.Int.ones n) = FStar.Int.lognot a) | {
"end_col": 75,
"end_line": 163,
"start_col": 26,
"start_line": 163
} |
FStar.Pervasives.Lemma | val logxor_commutative: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires True) (ensures (logxor #n a b = logxor #n b a)) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a) | val logxor_commutative: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires True) (ensures (logxor #n a b = logxor #n b a))
let logxor_commutative #n a b = | false | null | true | nth_lemma #n (logxor #n a b) (logxor #n b a) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logxor",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a
let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logxor_commutative: #n:pos -> a:int_t n -> b:int_t n ->
Lemma (requires True) (ensures (logxor #n a b = logxor #n b a)) | [] | FStar.Int.logxor_commutative | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> b: FStar.Int.int_t n
-> FStar.Pervasives.Lemma (ensures FStar.Int.logxor a b = FStar.Int.logxor b a) | {
"end_col": 76,
"end_line": 155,
"start_col": 32,
"start_line": 155
} |
FStar.Pervasives.Lemma | val logxor_neq_nonzero: #n:pos -> a:int_t n -> b:int_t n -> Lemma
(a <> b ==> logxor a b <> 0) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logxor_neq_nonzero #n a b =
UInt.logxor_neq_nonzero (to_uint a) (to_uint b) | val logxor_neq_nonzero: #n:pos -> a:int_t n -> b:int_t n -> Lemma
(a <> b ==> logxor a b <> 0)
let logxor_neq_nonzero #n a b = | false | null | true | UInt.logxor_neq_nonzero (to_uint a) (to_uint b) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.UInt.logxor_neq_nonzero",
"FStar.Int.to_uint",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a
let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let logxor_inv #n a b =
UInt.logxor_inv (to_uint a) (to_uint b) | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logxor_neq_nonzero: #n:pos -> a:int_t n -> b:int_t n -> Lemma
(a <> b ==> logxor a b <> 0) | [] | FStar.Int.logxor_neq_nonzero | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> b: FStar.Int.int_t n
-> FStar.Pervasives.Lemma (ensures a <> b ==> FStar.Int.logxor a b <> 0) | {
"end_col": 49,
"end_line": 169,
"start_col": 2,
"start_line": 169
} |
FStar.Pervasives.Lemma | val zero_to_vec_lemma: #n:pos -> i:nat{i < n} ->
Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i)
[SMTPat (index (to_vec (zero n)) i)] | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i | val zero_to_vec_lemma: #n:pos -> i:nat{i < n} ->
Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i)
[SMTPat (index (to_vec (zero n)) i)]
let rec zero_to_vec_lemma #n i = | false | null | true | if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Subtraction",
"Prims.bool",
"FStar.Int.zero_to_vec_lemma",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val zero_to_vec_lemma: #n:pos -> i:nat{i < n} ->
Lemma (requires True) (ensures index (to_vec (zero n)) i = index (zero_vec #n) i)
[SMTPat (index (to_vec (zero n)) i)] | [
"recursion"
] | FStar.Int.zero_to_vec_lemma | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.index (FStar.Int.to_vec (FStar.Int.zero n)) i =
FStar.Seq.Base.index FStar.BitVector.zero_vec i)
[SMTPat (FStar.Seq.Base.index (FStar.Int.to_vec (FStar.Int.zero n)) i)] | {
"end_col": 56,
"end_line": 83,
"start_col": 2,
"start_line": 83
} |
FStar.Pervasives.Lemma | val shift_left_value_lemma: #n:pos -> a:int_t n{0 <= a} -> s:nat ->
Lemma (requires True)
(ensures shift_left #n a s = (a * pow2 s) @% pow2 n)
[SMTPat (shift_left #n a s)] | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let shift_left_value_lemma #n a s =
UInt.shift_left_value_lemma #n a s | val shift_left_value_lemma: #n:pos -> a:int_t n{0 <= a} -> s:nat ->
Lemma (requires True)
(ensures shift_left #n a s = (a * pow2 s) @% pow2 n)
[SMTPat (shift_left #n a s)]
let shift_left_value_lemma #n a s = | false | null | true | UInt.shift_left_value_lemma #n a s | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.nat",
"FStar.UInt.shift_left_value_lemma",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a
let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2"
let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n))
#pop-options
let logxor_commutative #n a b = nth_lemma #n (logxor #n a b) (logxor #n b a)
let logxor_associative #n a b c = nth_lemma #n (logxor #n (logxor #n a b) c) (logxor #n a (logxor #n b c))
let logxor_self #n a = nth_lemma #n (logxor #n a a) (zero n)
let logxor_lemma_1 #n a = nth_lemma #n (logxor #n a (zero n)) a
let logxor_lemma_2 #n a = nth_lemma #n (logxor #n a (ones n)) (lognot #n a)
let logxor_inv #n a b =
UInt.logxor_inv (to_uint a) (to_uint b)
let logxor_neq_nonzero #n a b =
UInt.logxor_neq_nonzero (to_uint a) (to_uint b)
let lognot_negative #n a =
assert_norm (pow2 n = 2 * pow2 (n - 1));
UInt.lemma_lognot_value_mod #n (a + pow2 n)
let shift_left_lemma_1 #n a s i = ()
let shift_left_lemma_2 #n a s i = () | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val shift_left_value_lemma: #n:pos -> a:int_t n{0 <= a} -> s:nat ->
Lemma (requires True)
(ensures shift_left #n a s = (a * pow2 s) @% pow2 n)
[SMTPat (shift_left #n a s)] | [] | FStar.Int.shift_left_value_lemma | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n {0 <= a} -> s: Prims.nat
-> FStar.Pervasives.Lemma (ensures FStar.Int.shift_left a s = a * Prims.pow2 s @% Prims.pow2 n)
[SMTPat (FStar.Int.shift_left a s)] | {
"end_col": 36,
"end_line": 180,
"start_col": 2,
"start_line": 180
} |
FStar.Pervasives.Lemma | val one_to_vec_lemma: #n:pos{1 < n} -> i:nat{i < n} ->
Lemma (requires True)
(ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i)
[SMTPat (index (to_vec (one n)) i)] | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i | val one_to_vec_lemma: #n:pos{1 < n} -> i:nat{i < n} ->
Lemma (requires True)
(ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i)
[SMTPat (index (to_vec (one n)) i)]
let one_to_vec_lemma #n i = | false | null | true | if i = n - 1 then () else zero_to_vec_lemma #n i | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Subtraction",
"Prims.bool",
"FStar.Int.zero_to_vec_lemma",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n) | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val one_to_vec_lemma: #n:pos{1 < n} -> i:nat{i < n} ->
Lemma (requires True)
(ensures index (to_vec (one n)) i = index (elem_vec #n (n - 1)) i)
[SMTPat (index (to_vec (one n)) i)] | [] | FStar.Int.one_to_vec_lemma | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.index (FStar.Int.to_vec (FStar.Int.one n)) i =
FStar.Seq.Base.index (FStar.BitVector.elem_vec (n - 1)) i)
[SMTPat (FStar.Seq.Base.index (FStar.Int.to_vec (FStar.Int.one n)) i)] | {
"end_col": 50,
"end_line": 88,
"start_col": 2,
"start_line": 88
} |
FStar.Pervasives.Lemma | val pow2_to_vec_lemma: #n:pos -> p:nat{p < n-1} -> i:nat{i < n} ->
Lemma (requires True)
(ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i)
[SMTPat (index (to_vec (pow2_n #n p)) i)] | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i | val pow2_to_vec_lemma: #n:pos -> p:nat{p < n-1} -> i:nat{i < n} ->
Lemma (requires True)
(ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i)
[SMTPat (index (to_vec (pow2_n #n p)) i)]
let rec pow2_to_vec_lemma #n p i = | false | null | true | if i = n - 1
then ()
else if p = 0 then one_to_vec_lemma #n i else pow2_to_vec_lemma #(n - 1) (p - 1) i | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"FStar.Int.one_to_vec_lemma",
"FStar.Int.pow2_to_vec_lemma",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native" | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pow2_to_vec_lemma: #n:pos -> p:nat{p < n-1} -> i:nat{i < n} ->
Lemma (requires True)
(ensures index (to_vec (pow2_n #n p)) i = index (elem_vec #n (n - p - 1)) i)
[SMTPat (index (to_vec (pow2_n #n p)) i)] | [
"recursion"
] | FStar.Int.pow2_to_vec_lemma | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | p: Prims.nat{p < n - 1} -> i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.index (FStar.Int.to_vec (FStar.Int.pow2_n p)) i =
FStar.Seq.Base.index (FStar.BitVector.elem_vec (n - p - 1)) i)
[SMTPat (FStar.Seq.Base.index (FStar.Int.to_vec (FStar.Int.pow2_n p)) i)] | {
"end_col": 43,
"end_line": 94,
"start_col": 2,
"start_line": 92
} |
FStar.Pervasives.Lemma | val sign_bit_negative: #n:pos{1 < n} -> a:int_t n ->
Lemma (nth a 0 = true <==> a < 0) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1 | val sign_bit_negative: #n:pos{1 < n} -> a:int_t n ->
Lemma (nth a 0 = true <==> a < 0)
let sign_bit_negative #n a = | false | null | true | UInt.from_vec_propriety #n (to_vec a) 1 | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.int_t",
"FStar.UInt.from_vec_propriety",
"FStar.Int.to_vec",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sign_bit_negative: #n:pos{1 < n} -> a:int_t n ->
Lemma (nth a 0 = true <==> a < 0) | [] | FStar.Int.sign_bit_negative | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> FStar.Pervasives.Lemma (ensures FStar.Int.nth a 0 = true <==> a < 0) | {
"end_col": 41,
"end_line": 137,
"start_col": 2,
"start_line": 137
} |
FStar.Pervasives.Lemma | val sign_bit_positive: #n:pos{1 < n} -> a:int_t n ->
Lemma (nth a 0 = false <==> 0 <= a) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1 | val sign_bit_positive: #n:pos{1 < n} -> a:int_t n ->
Lemma (nth a 0 = false <==> 0 <= a)
let sign_bit_positive #n a = | false | null | true | UInt.from_vec_propriety #n (to_vec a) 1 | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.int_t",
"FStar.UInt.from_vec_propriety",
"FStar.Int.to_vec",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a
let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1 | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sign_bit_positive: #n:pos{1 < n} -> a:int_t n ->
Lemma (nth a 0 = false <==> 0 <= a) | [] | FStar.Int.sign_bit_positive | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> FStar.Pervasives.Lemma (ensures FStar.Int.nth a 0 = false <==> 0 <= a) | {
"end_col": 41,
"end_line": 140,
"start_col": 2,
"start_line": 140
} |
Prims.Pure | val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a - b) n ==> a - b = c)) | [
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sub_underspec #n a b =
if fits (a-b) n then a - b else 0 | val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a - b) n ==> a - b = c))
let sub_underspec #n a b = | false | null | false | if fits (a - b) n then a - b else 0 | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.fits",
"Prims.op_Subtraction",
"Prims.bool"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0 | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sub_underspec: #n:pos -> a:int_t n -> b:int_t n -> Pure (int_t n)
(requires True)
(ensures (fun c ->
size (a - b) n ==> a - b = c)) | [] | FStar.Int.sub_underspec | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n -> b: FStar.Int.int_t n -> Prims.Pure (FStar.Int.int_t n) | {
"end_col": 35,
"end_line": 47,
"start_col": 2,
"start_line": 47
} |
FStar.Pervasives.Lemma | val logand_max: #n:pos{1 < n} -> a:int_t n{0 <= a} ->
Lemma (0 <= logand a (max_int n) /\ a = logand a (max_int n)) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logand_max #n a =
sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n)) | val logand_max: #n:pos{1 < n} -> a:int_t n{0 <= a} ->
Lemma (0 <= logand a (max_int n) /\ a = logand a (max_int n))
let logand_max #n a = | false | null | true | sign_bit_positive a;
sign_bit_positive #n (max_int n);
nth_lemma a (logand a (max_int n)) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.int_t",
"Prims.op_LessThanOrEqual",
"FStar.Int.nth_lemma",
"FStar.Int.logand",
"FStar.Int.max_int",
"Prims.unit",
"FStar.Int.sign_bit_positive"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a
let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n)
let logand_lemma_2 #n a =
nth_lemma #n (logand #n a (ones n)) a
let sign_bit_negative #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let sign_bit_positive #n a =
UInt.from_vec_propriety #n (to_vec a) 1
let logand_pos_le #n a b =
UInt.logand_le (to_uint a) (to_uint b)
let logand_pow2_minus_one #n a m =
UInt.logand_le (to_uint a) (to_uint (pow2_minus_one #n m))
#push-options "--z3rlimit_factor 2" | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logand_max: #n:pos{1 < n} -> a:int_t n{0 <= a} ->
Lemma (0 <= logand a (max_int n) /\ a = logand a (max_int n)) | [] | FStar.Int.logand_max | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n {0 <= a}
-> FStar.Pervasives.Lemma
(ensures
0 <= FStar.Int.logand a (FStar.Int.max_int n) /\ a = FStar.Int.logand a (FStar.Int.max_int n)) | {
"end_col": 36,
"end_line": 152,
"start_col": 2,
"start_line": 150
} |
FStar.Pervasives.Lemma | val logand_lemma_1: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logand #n a (zero n) = zero n)) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let logand_lemma_1 #n a =
nth_lemma #n (logand #n a (zero n)) (zero n) | val logand_lemma_1: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logand #n a (zero n) = zero n))
let logand_lemma_1 #n a = | false | null | true | nth_lemma #n (logand #n a (zero n)) (zero n) | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.pos",
"FStar.Int.int_t",
"FStar.Int.nth_lemma",
"FStar.Int.logand",
"FStar.Int.zero",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1"
let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i
#pop-options
let inverse_vec_lemma #n vec = ()
let inverse_num_lemma #n num = ()
let from_vec_lemma_1 #n a b = ()
let from_vec_lemma_2 #n a b = inverse_vec_lemma a; inverse_vec_lemma b
let rec zero_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #(n - 1) i
let zero_from_vec_lemma #n = to_vec_lemma_2 (from_vec (zero_vec #n)) (zero n)
let one_to_vec_lemma #n i =
if i = n - 1 then () else zero_to_vec_lemma #n i
#push-options "--smtencoding.elim_box true --smtencoding.l_arith_repr native"
let rec pow2_to_vec_lemma #n p i =
if i = n - 1 then ()
else if p = 0 then one_to_vec_lemma #n i
else pow2_to_vec_lemma #(n - 1) (p - 1) i
#pop-options
let pow2_from_vec_lemma #n p =
to_vec_lemma_2 (from_vec (elem_vec #n p)) (pow2_n #n (n - p - 1))
let ones_to_vec_lemma #n i = ()
let ones_from_vec_lemma #n =
to_vec_lemma_2 (from_vec (ones_vec #n)) (ones n)
let nth_lemma #n a b =
assert(forall (i:nat{i < n}). index (to_vec #n a) i = index (to_vec #n b) i);
to_vec_lemma_2 a b
let zero_nth_lemma #n i = ()
let one_nth_lemma #n i = ()
let ones_nth_lemma #n i = ()
let logand_definition #n a b i = ()
let logxor_definition #n a b i = ()
let logor_definition #n a b i = ()
let lognot_definition #n a i = ()
let logand_commutative #n a b = nth_lemma #n (logand #n a b) (logand #n b a)
let logand_associative #n a b c =
nth_lemma #n (logand #n (logand #n a b) c) (logand #n a (logand #n b c))
let logand_self #n a = nth_lemma #n (logand #n a a) a | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val logand_lemma_1: #n:pos -> a:int_t n ->
Lemma (requires True) (ensures (logand #n a (zero n) = zero n)) | [] | FStar.Int.logand_lemma_1 | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a: FStar.Int.int_t n
-> FStar.Pervasives.Lemma (ensures FStar.Int.logand a (FStar.Int.zero n) = FStar.Int.zero n) | {
"end_col": 46,
"end_line": 131,
"start_col": 2,
"start_line": 131
} |
FStar.Pervasives.Lemma | val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} ->
Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i)
[SMTPat (index (to_vec (from_vec vec)) i)] | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BitVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec inverse_aux #n vec i =
if i = n - 1 then
assert((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i | val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} ->
Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i)
[SMTPat (index (to_vec (from_vec vec)) i)]
let rec inverse_aux #n vec i = | false | null | true | if i = n - 1
then assert ((from_vec vec) % 2 = (if index vec (n - 1) then 1 else 0))
else inverse_aux #(n - 1) (slice vec 0 (n - 1)) i | {
"checked_file": "FStar.Int.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lib.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.BitVector.fst.checked"
],
"interface_file": true,
"source_file": "FStar.Int.fst"
} | [
"lemma"
] | [
"Prims.nat",
"FStar.BitVector.bv_t",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Subtraction",
"Prims._assert",
"Prims.op_Modulus",
"FStar.Int.from_vec",
"FStar.Seq.Base.index",
"Prims.bool",
"FStar.Int.inverse_aux",
"FStar.Seq.Base.slice",
"Prims.unit"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Int
(* NOTE: anything that you fix/update here should be reflected in [FStar.UInt.fst], which is mostly
* a copy-paste of this module. *)
open FStar.Mul
open FStar.BitVector
open FStar.Math.Lemmas
let pow2_values x =
match x with
| 0 -> assert_norm (pow2 0 == 1)
| 1 -> assert_norm (pow2 1 == 2)
| 8 -> assert_norm (pow2 8 == 256)
| 16 -> assert_norm (pow2 16 == 65536)
| 31 -> assert_norm (pow2 31 == 2147483648)
| 32 -> assert_norm (pow2 32 == 4294967296)
| 63 -> assert_norm (pow2 63 == 9223372036854775808)
| 64 -> assert_norm (pow2 64 == 18446744073709551616)
| _ -> ()
let incr_underspec #n a =
if a < max_int n then a + 1 else 0
let decr_underspec #n a =
if a > min_int n then a - 1 else 0
let add_underspec #n a b =
if fits (a+b) n then a + b else 0
let sub_underspec #n a b =
if fits (a-b) n then a - b else 0
let mul_underspec #n a b =
if fits (a*b) n then a * b else 0
let div_underspec #n a b =
if fits (a / b) n then a / b else 0
let div_size #n a b =
FStar.Math.Lib.slash_decr_axiom (abs a) (abs b)
let to_uint_injective #n x = ()
open FStar.Seq
let to_vec_lemma_1 #n a b = ()
let to_vec_lemma_2 #n a b =
UInt.to_vec_lemma_2 #n (to_uint a) (to_uint b)
#push-options "--initial_fuel 1 --max_fuel 1" | false | false | FStar.Int.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val inverse_aux: #n:nat -> vec:bv_t n -> i:nat{i < n} ->
Lemma (requires True) (ensures index vec i = index (to_vec (from_vec vec)) i)
[SMTPat (index (to_vec (from_vec vec)) i)] | [
"recursion"
] | FStar.Int.inverse_aux | {
"file_name": "ulib/FStar.Int.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | vec: FStar.BitVector.bv_t n -> i: Prims.nat{i < n}
-> FStar.Pervasives.Lemma
(ensures
FStar.Seq.Base.index vec i =
FStar.Seq.Base.index (FStar.Int.to_vec (FStar.Int.from_vec vec)) i)
[SMTPat (FStar.Seq.Base.index (FStar.Int.to_vec (FStar.Int.from_vec vec)) i)] | {
"end_col": 51,
"end_line": 71,
"start_col": 2,
"start_line": 69
} |
FStar.Tactics.Effect.Tac | val implies_intro: Prims.unit -> Tac binding | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro () | val implies_intro: Prims.unit -> Tac binding
let implies_intro () : Tac binding = | true | null | false | apply_lemma (`imp_intro_lem);
intro () | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Builtins.intro",
"FStar.Reflection.V2.Data.binding",
"FStar.Tactics.V2.Derived.apply_lemma",
"FStar.Tactics.NamedView.binding"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *) | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val implies_intro: Prims.unit -> Tac binding | [] | FStar.Tactics.V2.Logic.implies_intro | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | {
"end_col": 12,
"end_line": 81,
"start_col": 4,
"start_line": 80
} |
FStar.Tactics.Effect.Tac | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t) | let l_exact (t: term) = | true | null | false | try exact t
with
| _ ->
(squash_intro ();
exact t) | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.try_with",
"Prims.unit",
"FStar.Tactics.V2.Derived.exact",
"Prims.exn",
"FStar.Tactics.V2.Logic.squash_intro"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash) | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val l_exact : t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | [] | FStar.Tactics.V2.Logic.l_exact | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 37,
"end_line": 101,
"start_col": 4,
"start_line": 100
} |
|
FStar.Tactics.Effect.Tac | val l_revert: Prims.unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let l_revert () : Tac unit =
revert ();
apply (`revert_squash) | val l_revert: Prims.unit -> Tac unit
let l_revert () : Tac unit = | true | null | false | revert ();
apply (`revert_squash) | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.apply",
"FStar.Tactics.V2.Builtins.revert"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *) | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val l_revert: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Logic.l_revert | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 26,
"end_line": 38,
"start_col": 4,
"start_line": 37
} |
FStar.Tactics.Effect.Tac | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let l_intros () = repeat l_intro | let l_intros () = | true | null | false | repeat l_intro | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.repeat",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.l_intro",
"Prims.list"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val l_intros : _: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.binding) | [] | FStar.Tactics.V2.Logic.l_intros | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.binding) | {
"end_col": 32,
"end_line": 94,
"start_col": 18,
"start_line": 94
} |
|
FStar.Tactics.Effect.Tac | val cur_formula: Prims.unit -> Tac formula | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let cur_formula () : Tac formula = term_as_formula (cur_goal ()) | val cur_formula: Prims.unit -> Tac formula
let cur_formula () : Tac formula = | true | null | false | term_as_formula (cur_goal ()) | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.unit",
"FStar.Reflection.V2.Formula.term_as_formula",
"FStar.Reflection.V2.Formula.formula",
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.cur_goal",
"FStar.Reflection.Types.typ"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val cur_formula: Prims.unit -> Tac formula | [] | FStar.Tactics.V2.Logic.cur_formula | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Reflection.V2.Formula.formula | {
"end_col": 64,
"end_line": 28,
"start_col": 35,
"start_line": 28
} |
FStar.Tactics.Effect.Tac | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let l_intro () = forall_intro `or_else` implies_intro | let l_intro () = | true | null | false | forall_intro `or_else` implies_intro | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.or_else",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.forall_intro",
"FStar.Tactics.V2.Logic.implies_intro"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val l_intro : _: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | [] | FStar.Tactics.V2.Logic.l_intro | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | {
"end_col": 53,
"end_line": 91,
"start_col": 17,
"start_line": 91
} |
|
FStar.Tactics.Effect.Tac | val forall_intros: Prims.unit -> Tac (list binding) | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let forall_intros () : Tac (list binding) = repeat1 forall_intro | val forall_intros: Prims.unit -> Tac (list binding)
let forall_intros () : Tac (list binding) = | true | null | false | repeat1 forall_intro | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.repeat1",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.forall_intro",
"Prims.list"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val forall_intros: Prims.unit -> Tac (list binding) | [] | FStar.Tactics.V2.Logic.forall_intros | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.binding) | {
"end_col": 64,
"end_line": 61,
"start_col": 44,
"start_line": 61
} |
FStar.Pervasives.Lemma | val fa_intro_lem (#a: Type) (#p: (a -> Type)) (f: (x: a -> squash (p x)))
: Lemma (forall (x: a). p x) | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x))) | val fa_intro_lem (#a: Type) (#p: (a -> Type)) (f: (x: a -> squash (p x)))
: Lemma (forall (x: a). p x)
let fa_intro_lem (#a: Type) (#p: (a -> Type)) (f: (x: a -> squash (p x)))
: Lemma (forall (x: a). p x) = | false | null | true | FStar.Classical.lemma_forall_intro_gtot ((fun x -> FStar.IndefiniteDescription.elim_squash (f x))
<:
(x: a -> GTot (p x))) | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
"lemma"
] | [
"Prims.squash",
"FStar.Classical.lemma_forall_intro_gtot",
"FStar.IndefiniteDescription.elim_squash",
"Prims.unit",
"Prims.l_True",
"Prims.l_Forall",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val fa_intro_lem (#a: Type) (#p: (a -> Type)) (f: (x: a -> squash (p x)))
: Lemma (forall (x: a). p x) | [] | FStar.Tactics.V2.Logic.fa_intro_lem | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | f: (x: a -> Prims.squash (p x)) -> FStar.Pervasives.Lemma (ensures forall (x: a). p x) | {
"end_col": 85,
"end_line": 48,
"start_col": 2,
"start_line": 47
} |
FStar.Tactics.Effect.Tac | val implies_intro_as (s: string) : Tac binding | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s | val implies_intro_as (s: string) : Tac binding
let implies_intro_as (s: string) : Tac binding = | true | null | false | apply_lemma (`imp_intro_lem);
intro_as s | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.string",
"FStar.Tactics.V2.Derived.intro_as",
"FStar.Tactics.NamedView.binding",
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro () | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val implies_intro_as (s: string) : Tac binding | [] | FStar.Tactics.V2.Logic.implies_intro_as | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: Prims.string -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | {
"end_col": 14,
"end_line": 85,
"start_col": 4,
"start_line": 84
} |
FStar.Tactics.Effect.Tac | val destruct_and (t: term) : Tac (binding * binding) | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let destruct_and (t : term) : Tac (binding * binding) =
and_elim t;
(implies_intro (), implies_intro ()) | val destruct_and (t: term) : Tac (binding * binding)
let destruct_and (t: term) : Tac (binding * binding) = | true | null | false | and_elim t;
(implies_intro (), implies_intro ()) | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Tactics.NamedView.binding",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V2.Logic.implies_intro",
"Prims.unit",
"FStar.Tactics.V2.Logic.and_elim"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = ()
let left () : Tac unit =
apply_lemma (`or_intro_1)
let right () : Tac unit =
apply_lemma (`or_intro_2)
private val __and_elim : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim #p #q #phi p_and_q f = ()
private val __and_elim' : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
squash (p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim' #p #q #phi p_and_q f = ()
let and_elim (t : term) : Tac unit =
begin
try apply_lemma (`(__and_elim (`#t)))
with | _ -> apply_lemma (`(__and_elim' (`#t)))
end | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val destruct_and (t: term) : Tac (binding * binding) | [] | FStar.Tactics.V2.Logic.destruct_and | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Tactics.NamedView.term
-> FStar.Tactics.Effect.Tac (FStar.Tactics.NamedView.binding * FStar.Tactics.NamedView.binding) | {
"end_col": 40,
"end_line": 263,
"start_col": 4,
"start_line": 262
} |
FStar.Tactics.Effect.Tac | val witness (t: term) : Tac unit | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let witness (t : term) : Tac unit =
apply_raw (`__witness);
exact t | val witness (t: term) : Tac unit
let witness (t: term) : Tac unit = | true | null | false | apply_raw (`__witness);
exact t | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"FStar.Tactics.NamedView.term",
"FStar.Tactics.V2.Derived.exact",
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_raw"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = ()
let left () : Tac unit =
apply_lemma (`or_intro_1)
let right () : Tac unit =
apply_lemma (`or_intro_2)
private val __and_elim : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim #p #q #phi p_and_q f = ()
private val __and_elim' : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
squash (p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim' #p #q #phi p_and_q f = ()
let and_elim (t : term) : Tac unit =
begin
try apply_lemma (`(__and_elim (`#t)))
with | _ -> apply_lemma (`(__and_elim' (`#t)))
end
let destruct_and (t : term) : Tac (binding * binding) =
and_elim t;
(implies_intro (), implies_intro ())
private val __witness : (#a:Type) -> (x:a) -> (#p:(a -> Type)) -> squash (p x) -> squash (exists (x:a). p x)
private let __witness #a x #p _ = () | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val witness (t: term) : Tac unit | [] | FStar.Tactics.V2.Logic.witness | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 11,
"end_line": 270,
"start_col": 4,
"start_line": 269
} |
FStar.Tactics.Effect.Tac | val split: Prims.unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal" | val split: Prims.unit -> Tac unit
let split () : Tac unit = | true | null | false | try apply_lemma (`split_lem) with | _ -> fail "Could not split goal" | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.try_with",
"FStar.Tactics.V2.Derived.apply_lemma",
"Prims.exn",
"FStar.Tactics.V2.Derived.fail"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *) | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val split: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Logic.split | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 43,
"end_line": 70,
"start_col": 4,
"start_line": 69
} |
FStar.Tactics.Effect.Tac | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sk_binder b = sk_binder' [] b | let sk_binder b = | true | null | false | sk_binder' [] b | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.sk_binder'",
"Prims.Nil",
"FStar.Pervasives.Native.tuple2",
"Prims.list"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = ()
let left () : Tac unit =
apply_lemma (`or_intro_1)
let right () : Tac unit =
apply_lemma (`or_intro_2)
private val __and_elim : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim #p #q #phi p_and_q f = ()
private val __and_elim' : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
squash (p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim' #p #q #phi p_and_q f = ()
let and_elim (t : term) : Tac unit =
begin
try apply_lemma (`(__and_elim (`#t)))
with | _ -> apply_lemma (`(__and_elim' (`#t)))
end
let destruct_and (t : term) : Tac (binding * binding) =
and_elim t;
(implies_intro (), implies_intro ())
private val __witness : (#a:Type) -> (x:a) -> (#p:(a -> Type)) -> squash (p x) -> squash (exists (x:a). p x)
private let __witness #a x #p _ = ()
let witness (t : term) : Tac unit =
apply_raw (`__witness);
exact t
private
let __elim_exists' #t (#pred : t -> Type0) #goal (h : (exists x. pred x))
(k : (x:t -> pred x -> squash goal)) : squash goal =
FStar.Squash.bind_squash #(x:t & pred x) h (fun (|x, pf|) -> k x pf)
(* returns witness and proof as binders *)
let elim_exists (t : term) : Tac (binding & binding) =
apply_lemma (`(__elim_exists' (`#(t))));
let x = intro () in
let pf = intro () in
(x, pf)
private
let __forall_inst #t (#pred : t -> Type0) (h : (forall x. pred x)) (x : t) : squash (pred x) =
()
(* GM: annoying that this doesn't just work by SMT *)
private
let __forall_inst_sq #t (#pred : t -> Type0) (h : squash (forall x. pred x)) (x : t) : squash (pred x) =
FStar.Squash.bind_squash h (fun (f : (forall x. pred x)) -> __forall_inst f x)
let instantiate (fa : term) (x : term) : Tac binding =
try pose (`__forall_inst_sq (`#fa) (`#x)) with | _ ->
try pose (`__forall_inst (`#fa) (`#x)) with | _ ->
fail "could not instantiate"
let instantiate_as (fa : term) (x : term) (s : string) : Tac binding =
let b = instantiate fa x in
rename_to b s
private
let sklem0 (#a:Type) (#p : a -> Type0) ($v : (exists (x:a). p x)) (phi:Type0) :
Lemma (requires (forall x. p x ==> phi))
(ensures phi) = ()
private
let rec sk_binder' (acc:list binding) (b:binding) : Tac (list binding & binding) =
focus (fun () ->
try
apply_lemma (`(sklem0 (`#b)));
if ngoals () <> 1 then fail "no";
clear b;
let bx = forall_intro () in
let b' = implies_intro () in
sk_binder' (bx::acc) b' (* We might have introduced a new existential, so possibly recurse *)
with | _ -> (acc, b) (* If the above failed, just return *)
)
(* Skolemizes a given binder for an existential, returning the introduced new binders | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sk_binder : b: FStar.Tactics.NamedView.binding
-> FStar.Tactics.Effect.Tac
(Prims.list FStar.Tactics.NamedView.binding * FStar.Tactics.NamedView.binding) | [] | FStar.Tactics.V2.Logic.sk_binder | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | b: FStar.Tactics.NamedView.binding
-> FStar.Tactics.Effect.Tac
(Prims.list FStar.Tactics.NamedView.binding * FStar.Tactics.NamedView.binding) | {
"end_col": 33,
"end_line": 322,
"start_col": 18,
"start_line": 322
} |
|
FStar.Tactics.Effect.Tac | val implies_intros: Prims.unit -> Tac (list binding) | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let implies_intros () : Tac (list binding) = repeat1 implies_intro | val implies_intros: Prims.unit -> Tac (list binding)
let implies_intros () : Tac (list binding) = | true | null | false | repeat1 implies_intro | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.repeat1",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.implies_intro",
"Prims.list"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val implies_intros: Prims.unit -> Tac (list binding) | [] | FStar.Tactics.V2.Logic.implies_intros | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac (Prims.list FStar.Tactics.NamedView.binding) | {
"end_col": 66,
"end_line": 88,
"start_col": 45,
"start_line": 88
} |
FStar.Tactics.Effect.Tac | val squash_intro: Prims.unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash) | val squash_intro: Prims.unit -> Tac unit
let squash_intro () : Tac unit = | true | null | false | apply (`FStar.Squash.return_squash) | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.apply"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val squash_intro: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Logic.squash_intro | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 39,
"end_line": 97,
"start_col": 4,
"start_line": 97
} |
FStar.Tactics.Effect.Tac | val rewrite_all_equalities: Prims.unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication | val rewrite_all_equalities: Prims.unit -> Tac unit
let rewrite_all_equalities () : Tac unit = | true | null | false | visit simplify_eq_implication | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Logic.visit",
"FStar.Tactics.V2.Logic.simplify_eq_implication"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rewrite_all_equalities: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Logic.rewrite_all_equalities | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 33,
"end_line": 170,
"start_col": 4,
"start_line": 170
} |
Prims.Tot | val __forall_inst_sq (#t: _) (#pred: (t -> Type0)) (h: squash (forall x. pred x)) (x: t)
: squash (pred x) | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let __forall_inst_sq #t (#pred : t -> Type0) (h : squash (forall x. pred x)) (x : t) : squash (pred x) =
FStar.Squash.bind_squash h (fun (f : (forall x. pred x)) -> __forall_inst f x) | val __forall_inst_sq (#t: _) (#pred: (t -> Type0)) (h: squash (forall x. pred x)) (x: t)
: squash (pred x)
let __forall_inst_sq #t (#pred: (t -> Type0)) (h: squash (forall x. pred x)) (x: t)
: squash (pred x) = | false | null | true | FStar.Squash.bind_squash h (fun (f: (forall x. pred x)) -> __forall_inst f x) | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
"total"
] | [
"Prims.squash",
"Prims.l_Forall",
"FStar.Squash.bind_squash",
"FStar.Tactics.V2.Logic.__forall_inst"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = ()
let left () : Tac unit =
apply_lemma (`or_intro_1)
let right () : Tac unit =
apply_lemma (`or_intro_2)
private val __and_elim : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim #p #q #phi p_and_q f = ()
private val __and_elim' : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
squash (p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim' #p #q #phi p_and_q f = ()
let and_elim (t : term) : Tac unit =
begin
try apply_lemma (`(__and_elim (`#t)))
with | _ -> apply_lemma (`(__and_elim' (`#t)))
end
let destruct_and (t : term) : Tac (binding * binding) =
and_elim t;
(implies_intro (), implies_intro ())
private val __witness : (#a:Type) -> (x:a) -> (#p:(a -> Type)) -> squash (p x) -> squash (exists (x:a). p x)
private let __witness #a x #p _ = ()
let witness (t : term) : Tac unit =
apply_raw (`__witness);
exact t
private
let __elim_exists' #t (#pred : t -> Type0) #goal (h : (exists x. pred x))
(k : (x:t -> pred x -> squash goal)) : squash goal =
FStar.Squash.bind_squash #(x:t & pred x) h (fun (|x, pf|) -> k x pf)
(* returns witness and proof as binders *)
let elim_exists (t : term) : Tac (binding & binding) =
apply_lemma (`(__elim_exists' (`#(t))));
let x = intro () in
let pf = intro () in
(x, pf)
private
let __forall_inst #t (#pred : t -> Type0) (h : (forall x. pred x)) (x : t) : squash (pred x) =
()
(* GM: annoying that this doesn't just work by SMT *)
private | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val __forall_inst_sq (#t: _) (#pred: (t -> Type0)) (h: squash (forall x. pred x)) (x: t)
: squash (pred x) | [] | FStar.Tactics.V2.Logic.__forall_inst_sq | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | h: Prims.squash (forall (x: t). pred x) -> x: t -> Prims.squash (pred x) | {
"end_col": 82,
"end_line": 291,
"start_col": 4,
"start_line": 291
} |
FStar.Tactics.Effect.Tac | val forall_intro_as (s: string) : Tac binding | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s | val forall_intro_as (s: string) : Tac binding
let forall_intro_as (s: string) : Tac binding = | true | null | false | apply_lemma (`fa_intro_lem);
intro_as s | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.string",
"FStar.Tactics.V2.Derived.intro_as",
"FStar.Tactics.NamedView.binding",
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *) | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val forall_intro_as (s: string) : Tac binding | [] | FStar.Tactics.V2.Logic.forall_intro_as | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | s: Prims.string -> FStar.Tactics.Effect.Tac FStar.Tactics.NamedView.binding | {
"end_col": 14,
"end_line": 58,
"start_col": 4,
"start_line": 57
} |
FStar.Tactics.Effect.Tac | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let easy_fill () =
let _ = repeat intro in
(* If the goal is `a -> Lemma b`, intro will fail, try to use this switch *)
let _ = trytac (fun () -> apply (`lemma_from_squash); intro ()) in
smt () | let easy_fill () = | true | null | false | let _ = repeat intro in
let _ =
trytac (fun () ->
apply (`lemma_from_squash);
intro ())
in
smt () | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.smt",
"FStar.Pervasives.Native.option",
"FStar.Reflection.V2.Data.binding",
"FStar.Tactics.V2.Derived.trytac",
"FStar.Tactics.V2.Builtins.intro",
"FStar.Tactics.V2.Derived.apply",
"Prims.list",
"FStar.Tactics.V2.Derived.repeat"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = ()
let left () : Tac unit =
apply_lemma (`or_intro_1)
let right () : Tac unit =
apply_lemma (`or_intro_2)
private val __and_elim : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim #p #q #phi p_and_q f = ()
private val __and_elim' : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
squash (p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim' #p #q #phi p_and_q f = ()
let and_elim (t : term) : Tac unit =
begin
try apply_lemma (`(__and_elim (`#t)))
with | _ -> apply_lemma (`(__and_elim' (`#t)))
end
let destruct_and (t : term) : Tac (binding * binding) =
and_elim t;
(implies_intro (), implies_intro ())
private val __witness : (#a:Type) -> (x:a) -> (#p:(a -> Type)) -> squash (p x) -> squash (exists (x:a). p x)
private let __witness #a x #p _ = ()
let witness (t : term) : Tac unit =
apply_raw (`__witness);
exact t
private
let __elim_exists' #t (#pred : t -> Type0) #goal (h : (exists x. pred x))
(k : (x:t -> pred x -> squash goal)) : squash goal =
FStar.Squash.bind_squash #(x:t & pred x) h (fun (|x, pf|) -> k x pf)
(* returns witness and proof as binders *)
let elim_exists (t : term) : Tac (binding & binding) =
apply_lemma (`(__elim_exists' (`#(t))));
let x = intro () in
let pf = intro () in
(x, pf)
private
let __forall_inst #t (#pred : t -> Type0) (h : (forall x. pred x)) (x : t) : squash (pred x) =
()
(* GM: annoying that this doesn't just work by SMT *)
private
let __forall_inst_sq #t (#pred : t -> Type0) (h : squash (forall x. pred x)) (x : t) : squash (pred x) =
FStar.Squash.bind_squash h (fun (f : (forall x. pred x)) -> __forall_inst f x)
let instantiate (fa : term) (x : term) : Tac binding =
try pose (`__forall_inst_sq (`#fa) (`#x)) with | _ ->
try pose (`__forall_inst (`#fa) (`#x)) with | _ ->
fail "could not instantiate"
let instantiate_as (fa : term) (x : term) (s : string) : Tac binding =
let b = instantiate fa x in
rename_to b s
private
let sklem0 (#a:Type) (#p : a -> Type0) ($v : (exists (x:a). p x)) (phi:Type0) :
Lemma (requires (forall x. p x ==> phi))
(ensures phi) = ()
private
let rec sk_binder' (acc:list binding) (b:binding) : Tac (list binding & binding) =
focus (fun () ->
try
apply_lemma (`(sklem0 (`#b)));
if ngoals () <> 1 then fail "no";
clear b;
let bx = forall_intro () in
let b' = implies_intro () in
sk_binder' (bx::acc) b' (* We might have introduced a new existential, so possibly recurse *)
with | _ -> (acc, b) (* If the above failed, just return *)
)
(* Skolemizes a given binder for an existential, returning the introduced new binders
* and the skolemized formula. *)
let sk_binder b = sk_binder' [] b
let skolem () =
let bs = vars_of_env (cur_env ()) in
map sk_binder bs
private
val lemma_from_squash : #a:Type -> #b:(a -> Type) -> (x:a -> squash (b x)) -> x:a -> Lemma (b x)
private
let lemma_from_squash #a #b f x = let _ = f x in assert (b x) | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val easy_fill : _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | [] | FStar.Tactics.V2.Logic.easy_fill | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 10,
"end_line": 338,
"start_col": 18,
"start_line": 334
} |
|
FStar.Pervasives.Lemma | val lem1_fa (#a #pre #post: _) ($lem: (x: a -> Lemma (requires pre x) (ensures post x)))
: Lemma (forall (x: a). pre x ==> post x) | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let lem1_fa #a #pre #post
($lem : (x:a -> Lemma (requires pre x) (ensures post x))) :
Lemma (forall (x:a). pre x ==> post x) =
let l' x : Lemma (pre x ==> post x) =
Classical.move_requires lem x
in
Classical.forall_intro l' | val lem1_fa (#a #pre #post: _) ($lem: (x: a -> Lemma (requires pre x) (ensures post x)))
: Lemma (forall (x: a). pre x ==> post x)
let lem1_fa #a #pre #post ($lem: (x: a -> Lemma (requires pre x) (ensures post x)))
: Lemma (forall (x: a). pre x ==> post x) = | false | null | true | let l' x : Lemma (pre x ==> post x) = Classical.move_requires lem x in
Classical.forall_intro l' | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
"lemma"
] | [
"Prims.unit",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"FStar.Classical.forall_intro",
"Prims.l_imp",
"Prims.l_True",
"FStar.Classical.move_requires",
"Prims.l_Forall"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = ()
let left () : Tac unit =
apply_lemma (`or_intro_1)
let right () : Tac unit =
apply_lemma (`or_intro_2)
private val __and_elim : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim #p #q #phi p_and_q f = ()
private val __and_elim' : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
squash (p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim' #p #q #phi p_and_q f = ()
let and_elim (t : term) : Tac unit =
begin
try apply_lemma (`(__and_elim (`#t)))
with | _ -> apply_lemma (`(__and_elim' (`#t)))
end
let destruct_and (t : term) : Tac (binding * binding) =
and_elim t;
(implies_intro (), implies_intro ())
private val __witness : (#a:Type) -> (x:a) -> (#p:(a -> Type)) -> squash (p x) -> squash (exists (x:a). p x)
private let __witness #a x #p _ = ()
let witness (t : term) : Tac unit =
apply_raw (`__witness);
exact t
private
let __elim_exists' #t (#pred : t -> Type0) #goal (h : (exists x. pred x))
(k : (x:t -> pred x -> squash goal)) : squash goal =
FStar.Squash.bind_squash #(x:t & pred x) h (fun (|x, pf|) -> k x pf)
(* returns witness and proof as binders *)
let elim_exists (t : term) : Tac (binding & binding) =
apply_lemma (`(__elim_exists' (`#(t))));
let x = intro () in
let pf = intro () in
(x, pf)
private
let __forall_inst #t (#pred : t -> Type0) (h : (forall x. pred x)) (x : t) : squash (pred x) =
()
(* GM: annoying that this doesn't just work by SMT *)
private
let __forall_inst_sq #t (#pred : t -> Type0) (h : squash (forall x. pred x)) (x : t) : squash (pred x) =
FStar.Squash.bind_squash h (fun (f : (forall x. pred x)) -> __forall_inst f x)
let instantiate (fa : term) (x : term) : Tac binding =
try pose (`__forall_inst_sq (`#fa) (`#x)) with | _ ->
try pose (`__forall_inst (`#fa) (`#x)) with | _ ->
fail "could not instantiate"
let instantiate_as (fa : term) (x : term) (s : string) : Tac binding =
let b = instantiate fa x in
rename_to b s
private
let sklem0 (#a:Type) (#p : a -> Type0) ($v : (exists (x:a). p x)) (phi:Type0) :
Lemma (requires (forall x. p x ==> phi))
(ensures phi) = ()
private
let rec sk_binder' (acc:list binding) (b:binding) : Tac (list binding & binding) =
focus (fun () ->
try
apply_lemma (`(sklem0 (`#b)));
if ngoals () <> 1 then fail "no";
clear b;
let bx = forall_intro () in
let b' = implies_intro () in
sk_binder' (bx::acc) b' (* We might have introduced a new existential, so possibly recurse *)
with | _ -> (acc, b) (* If the above failed, just return *)
)
(* Skolemizes a given binder for an existential, returning the introduced new binders
* and the skolemized formula. *)
let sk_binder b = sk_binder' [] b
let skolem () =
let bs = vars_of_env (cur_env ()) in
map sk_binder bs
private
val lemma_from_squash : #a:Type -> #b:(a -> Type) -> (x:a -> squash (b x)) -> x:a -> Lemma (b x)
private
let lemma_from_squash #a #b f x = let _ = f x in assert (b x)
private
let easy_fill () =
let _ = repeat intro in
(* If the goal is `a -> Lemma b`, intro will fail, try to use this switch *)
let _ = trytac (fun () -> apply (`lemma_from_squash); intro ()) in
smt ()
val easy : #a:Type -> (#[easy_fill ()] _ : a) -> a
let easy #a #x = x
private
let lem1_fa #a #pre #post | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val lem1_fa (#a #pre #post: _) ($lem: (x: a -> Lemma (requires pre x) (ensures post x)))
: Lemma (forall (x: a). pre x ==> post x) | [] | FStar.Tactics.V2.Logic.lem1_fa | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | $lem: (x: a -> FStar.Pervasives.Lemma (requires pre x) (ensures post x))
-> FStar.Pervasives.Lemma (ensures forall (x: a). pre x ==> post x) | {
"end_col": 27,
"end_line": 350,
"start_col": 42,
"start_line": 346
} |
FStar.Tactics.Effect.Tac | val left: Prims.unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let left () : Tac unit =
apply_lemma (`or_intro_1) | val left: Prims.unit -> Tac unit
let left () : Tac unit = | true | null | false | apply_lemma (`or_intro_1) | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Derived.apply_lemma"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = () | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val left: Prims.unit -> Tac unit | [] | FStar.Tactics.V2.Logic.left | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 29,
"end_line": 238,
"start_col": 4,
"start_line": 238
} |
Prims.Tot | val easy : #a:Type -> (#[easy_fill ()] _ : a) -> a | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let easy #a #x = x | val easy : #a:Type -> (#[easy_fill ()] _ : a) -> a
let easy #a #x = | false | null | false | x | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [
"total"
] | [] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = ()
let left () : Tac unit =
apply_lemma (`or_intro_1)
let right () : Tac unit =
apply_lemma (`or_intro_2)
private val __and_elim : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim #p #q #phi p_and_q f = ()
private val __and_elim' : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
squash (p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim' #p #q #phi p_and_q f = ()
let and_elim (t : term) : Tac unit =
begin
try apply_lemma (`(__and_elim (`#t)))
with | _ -> apply_lemma (`(__and_elim' (`#t)))
end
let destruct_and (t : term) : Tac (binding * binding) =
and_elim t;
(implies_intro (), implies_intro ())
private val __witness : (#a:Type) -> (x:a) -> (#p:(a -> Type)) -> squash (p x) -> squash (exists (x:a). p x)
private let __witness #a x #p _ = ()
let witness (t : term) : Tac unit =
apply_raw (`__witness);
exact t
private
let __elim_exists' #t (#pred : t -> Type0) #goal (h : (exists x. pred x))
(k : (x:t -> pred x -> squash goal)) : squash goal =
FStar.Squash.bind_squash #(x:t & pred x) h (fun (|x, pf|) -> k x pf)
(* returns witness and proof as binders *)
let elim_exists (t : term) : Tac (binding & binding) =
apply_lemma (`(__elim_exists' (`#(t))));
let x = intro () in
let pf = intro () in
(x, pf)
private
let __forall_inst #t (#pred : t -> Type0) (h : (forall x. pred x)) (x : t) : squash (pred x) =
()
(* GM: annoying that this doesn't just work by SMT *)
private
let __forall_inst_sq #t (#pred : t -> Type0) (h : squash (forall x. pred x)) (x : t) : squash (pred x) =
FStar.Squash.bind_squash h (fun (f : (forall x. pred x)) -> __forall_inst f x)
let instantiate (fa : term) (x : term) : Tac binding =
try pose (`__forall_inst_sq (`#fa) (`#x)) with | _ ->
try pose (`__forall_inst (`#fa) (`#x)) with | _ ->
fail "could not instantiate"
let instantiate_as (fa : term) (x : term) (s : string) : Tac binding =
let b = instantiate fa x in
rename_to b s
private
let sklem0 (#a:Type) (#p : a -> Type0) ($v : (exists (x:a). p x)) (phi:Type0) :
Lemma (requires (forall x. p x ==> phi))
(ensures phi) = ()
private
let rec sk_binder' (acc:list binding) (b:binding) : Tac (list binding & binding) =
focus (fun () ->
try
apply_lemma (`(sklem0 (`#b)));
if ngoals () <> 1 then fail "no";
clear b;
let bx = forall_intro () in
let b' = implies_intro () in
sk_binder' (bx::acc) b' (* We might have introduced a new existential, so possibly recurse *)
with | _ -> (acc, b) (* If the above failed, just return *)
)
(* Skolemizes a given binder for an existential, returning the introduced new binders
* and the skolemized formula. *)
let sk_binder b = sk_binder' [] b
let skolem () =
let bs = vars_of_env (cur_env ()) in
map sk_binder bs
private
val lemma_from_squash : #a:Type -> #b:(a -> Type) -> (x:a -> squash (b x)) -> x:a -> Lemma (b x)
private
let lemma_from_squash #a #b f x = let _ = f x in assert (b x)
private
let easy_fill () =
let _ = repeat intro in
(* If the goal is `a -> Lemma b`, intro will fail, try to use this switch *)
let _ = trytac (fun () -> apply (`lemma_from_squash); intro ()) in
smt () | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val easy : #a:Type -> (#[easy_fill ()] _ : a) -> a | [] | FStar.Tactics.V2.Logic.easy | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | a | {
"end_col": 18,
"end_line": 341,
"start_col": 17,
"start_line": 341
} |
FStar.Tactics.Effect.Tac | [
{
"abbrev": false,
"full_module": "FStar.Tactics.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.NamedView",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.SyntaxCoercions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2.Formula",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let skolem () =
let bs = vars_of_env (cur_env ()) in
map sk_binder bs | let skolem () = | true | null | false | let bs = vars_of_env (cur_env ()) in
map sk_binder bs | {
"checked_file": "FStar.Tactics.V2.Logic.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.V2.SyntaxCoercions.fst.checked",
"FStar.Tactics.V2.Derived.fst.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Util.fst.checked",
"FStar.Tactics.NamedView.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Squash.fsti.checked",
"FStar.Reflection.V2.Formula.fst.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.IndefiniteDescription.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.V2.Logic.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.Util.map",
"FStar.Reflection.V2.Data.binding",
"FStar.Pervasives.Native.tuple2",
"Prims.list",
"FStar.Tactics.NamedView.binding",
"FStar.Tactics.V2.Logic.sk_binder",
"FStar.Reflection.V2.Builtins.vars_of_env",
"FStar.Reflection.Types.env",
"FStar.Tactics.V2.Derived.cur_env"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.V2.Logic
open FStar.Reflection.V2
open FStar.Reflection.V2.Formula
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.Tactics.V2.Derived
open FStar.Tactics.V2.SyntaxCoercions
open FStar.Tactics.NamedView
open FStar.Tactics.Util
(** Returns the current goal as a [formula]. *)
let cur_formula () : Tac formula = term_as_formula (cur_goal ())
private val revert_squash : (#a:Type) -> (#b : (a -> Type)) ->
(squash (forall (x:a). b x)) ->
x:a -> squash (b x)
let revert_squash #a #b s x = let x : (_:unit{forall x. b x}) = s in ()
(** Revert an introduced binder as a forall. *)
let l_revert () : Tac unit =
revert ();
apply (`revert_squash)
(** Repeated [l_revert]. *)
let rec l_revert_all (bs:list binding) : Tac unit =
match bs with
| [] -> ()
| _::tl -> begin l_revert (); l_revert_all tl end
private let fa_intro_lem (#a:Type) (#p:a -> Type) (f:(x:a -> squash (p x))) : Lemma (forall (x:a). p x) =
FStar.Classical.lemma_forall_intro_gtot
((fun x -> FStar.IndefiniteDescription.elim_squash (f x)) <: (x:a -> GTot (p x)))
(** Introduce a forall. *)
let forall_intro () : Tac binding =
apply_lemma (`fa_intro_lem);
intro ()
(** Introduce a forall, with some given name. *)
let forall_intro_as (s:string) : Tac binding =
apply_lemma (`fa_intro_lem);
intro_as s
(** Repeated [forall_intro]. *)
let forall_intros () : Tac (list binding) = repeat1 forall_intro
private val split_lem : (#a:Type) -> (#b:Type) ->
squash a -> squash b -> Lemma (a /\ b)
let split_lem #a #b sa sb = ()
(** Split a conjunction into two goals. *)
let split () : Tac unit =
try apply_lemma (`split_lem)
with | _ -> fail "Could not split goal"
private val imp_intro_lem : (#a:Type) -> (#b : Type) ->
(a -> squash b) ->
Lemma (a ==> b)
let imp_intro_lem #a #b f =
FStar.Classical.give_witness (FStar.Classical.arrow_to_impl (fun (x:squash a) -> FStar.Squash.bind_squash x f))
(** Introduce an implication. *)
let implies_intro () : Tac binding =
apply_lemma (`imp_intro_lem);
intro ()
let implies_intro_as (s:string) : Tac binding =
apply_lemma (`imp_intro_lem);
intro_as s
(** Repeated [implies_intro]. *)
let implies_intros () : Tac (list binding) = repeat1 implies_intro
(** "Logical" intro: introduce a forall or an implication. *)
let l_intro () = forall_intro `or_else` implies_intro
(** Repeated [l]. *)
let l_intros () = repeat l_intro
let squash_intro () : Tac unit =
apply (`FStar.Squash.return_squash)
let l_exact (t:term) =
try exact t with
| _ -> (squash_intro (); exact t)
// FIXME: should this take a binding? It's less general...
// but usually what we want. Coercions could help.
let hyp (x:namedv) : Tac unit = l_exact (namedv_to_term x)
private
let __lemma_to_squash #req #ens (_ : squash req) (h : (unit -> Lemma (requires req) (ensures ens))) : squash ens =
h ()
let pose_lemma (t : term) : Tac binding =
let c = tcc (cur_env ()) t in
let pre, post =
match c with
| C_Lemma pre post _ -> pre, post
| _ -> fail ""
in
let post = `((`#post) ()) in (* unthunk *)
let post = norm_term [] post in
(* If the precondition is trivial, do not cut by it *)
match term_as_formula' pre with
| True_ ->
pose (`(__lemma_to_squash #(`#pre) #(`#post) () (fun () -> (`#t))))
| _ ->
let reqb = tcut (`squash (`#pre)) in
let b = pose (`(__lemma_to_squash #(`#pre) #(`#post) (`#(reqb <: term)) (fun () -> (`#t)))) in
flip ();
ignore (trytac trivial);
b
let explode () : Tac unit =
ignore (
repeatseq (fun () -> first [(fun () -> ignore (l_intro ()));
(fun () -> ignore (split ()))]))
let rec visit (callback:unit -> Tac unit) : Tac unit =
focus (fun () ->
or_else callback
(fun () ->
let g = cur_goal () in
match term_as_formula g with
| Forall _b _sort _phi ->
let binders = forall_intros () in
seq (fun () -> visit callback) (fun () -> l_revert_all binders)
| And p q ->
seq split (fun () -> visit callback)
| Implies p q ->
let _ = implies_intro () in
seq (fun () -> visit callback) l_revert
| _ ->
()
)
)
let rec simplify_eq_implication () : Tac unit =
let e = cur_env () in
let g = cur_goal () in
let r = destruct_equality_implication g in
match r with
| None ->
fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in // G, eq_h:x=e |- P
rewrite eq_h; // G, eq_h:x=e |- P[e/x]
clear_top (); // G |- P[e/x]
visit simplify_eq_implication
let rewrite_all_equalities () : Tac unit =
visit simplify_eq_implication
let rec unfold_definition_and_simplify_eq (tm:term) : Tac unit =
let g = cur_goal () in
match term_as_formula g with
| App hd arg ->
if term_eq hd tm
then trivial ()
else ()
| _ -> begin
let r = destruct_equality_implication g in
match r with
| None -> fail "Not an equality implication"
| Some (_, rhs) ->
let eq_h = implies_intro () in
rewrite eq_h;
clear_top ();
visit (fun () -> unfold_definition_and_simplify_eq tm)
end
private val vbind : (#p:Type) -> (#q:Type) -> squash p -> (p -> squash q) -> Lemma q
let vbind #p #q sq f = FStar.Classical.give_witness_from_squash (FStar.Squash.bind_squash sq f)
(** A tactic to unsquash a hypothesis. Perhaps you are looking
for [unsquash_term].
Pre:
goal =
G |- e : squash s
t : squash r
Post:
G, x:r |- e : squash s
`x` is returned as a term
*)
let unsquash (t : term) : Tac term =
let v = `vbind in
apply_lemma (mk_e_app v [t]);
let b = intro () in
pack (Tv_Var b)
private val or_ind : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p \/ q) ->
(squash (p ==> phi)) ->
(squash (q ==> phi)) ->
Lemma phi
let or_ind #p #q #phi o l r = ()
let cases_or (o:term) : Tac unit =
apply_lemma (mk_e_app (`or_ind) [o])
private val bool_ind : (b:bool) -> (phi:Type) -> (squash (b == true ==> phi)) ->
(squash (b == false ==> phi)) ->
Lemma phi
let bool_ind b phi l r = ()
let cases_bool (b:term) : Tac unit =
let bi = `bool_ind in
seq (fun () -> apply_lemma (mk_e_app bi [b]))
(fun () -> let _ = trytac (fun () -> let b = implies_intro () in rewrite b; clear_top ()) in ())
private val or_intro_1 : (#p:Type) -> (#q:Type) -> squash p -> Lemma (p \/ q)
let or_intro_1 #p #q _ = ()
private val or_intro_2 : (#p:Type) -> (#q:Type) -> squash q -> Lemma (p \/ q)
let or_intro_2 #p #q _ = ()
let left () : Tac unit =
apply_lemma (`or_intro_1)
let right () : Tac unit =
apply_lemma (`or_intro_2)
private val __and_elim : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
(p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim #p #q #phi p_and_q f = ()
private val __and_elim' : (#p:Type) -> (#q:Type) -> (#phi:Type) ->
squash (p /\ q) ->
squash (p ==> q ==> phi) ->
Lemma phi
let __and_elim' #p #q #phi p_and_q f = ()
let and_elim (t : term) : Tac unit =
begin
try apply_lemma (`(__and_elim (`#t)))
with | _ -> apply_lemma (`(__and_elim' (`#t)))
end
let destruct_and (t : term) : Tac (binding * binding) =
and_elim t;
(implies_intro (), implies_intro ())
private val __witness : (#a:Type) -> (x:a) -> (#p:(a -> Type)) -> squash (p x) -> squash (exists (x:a). p x)
private let __witness #a x #p _ = ()
let witness (t : term) : Tac unit =
apply_raw (`__witness);
exact t
private
let __elim_exists' #t (#pred : t -> Type0) #goal (h : (exists x. pred x))
(k : (x:t -> pred x -> squash goal)) : squash goal =
FStar.Squash.bind_squash #(x:t & pred x) h (fun (|x, pf|) -> k x pf)
(* returns witness and proof as binders *)
let elim_exists (t : term) : Tac (binding & binding) =
apply_lemma (`(__elim_exists' (`#(t))));
let x = intro () in
let pf = intro () in
(x, pf)
private
let __forall_inst #t (#pred : t -> Type0) (h : (forall x. pred x)) (x : t) : squash (pred x) =
()
(* GM: annoying that this doesn't just work by SMT *)
private
let __forall_inst_sq #t (#pred : t -> Type0) (h : squash (forall x. pred x)) (x : t) : squash (pred x) =
FStar.Squash.bind_squash h (fun (f : (forall x. pred x)) -> __forall_inst f x)
let instantiate (fa : term) (x : term) : Tac binding =
try pose (`__forall_inst_sq (`#fa) (`#x)) with | _ ->
try pose (`__forall_inst (`#fa) (`#x)) with | _ ->
fail "could not instantiate"
let instantiate_as (fa : term) (x : term) (s : string) : Tac binding =
let b = instantiate fa x in
rename_to b s
private
let sklem0 (#a:Type) (#p : a -> Type0) ($v : (exists (x:a). p x)) (phi:Type0) :
Lemma (requires (forall x. p x ==> phi))
(ensures phi) = ()
private
let rec sk_binder' (acc:list binding) (b:binding) : Tac (list binding & binding) =
focus (fun () ->
try
apply_lemma (`(sklem0 (`#b)));
if ngoals () <> 1 then fail "no";
clear b;
let bx = forall_intro () in
let b' = implies_intro () in
sk_binder' (bx::acc) b' (* We might have introduced a new existential, so possibly recurse *)
with | _ -> (acc, b) (* If the above failed, just return *)
)
(* Skolemizes a given binder for an existential, returning the introduced new binders
* and the skolemized formula. *)
let sk_binder b = sk_binder' [] b | false | false | FStar.Tactics.V2.Logic.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val skolem : _: Prims.unit
-> FStar.Tactics.Effect.Tac
(Prims.list (Prims.list FStar.Tactics.NamedView.binding * FStar.Tactics.NamedView.binding)) | [] | FStar.Tactics.V2.Logic.skolem | {
"file_name": "ulib/FStar.Tactics.V2.Logic.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit
-> FStar.Tactics.Effect.Tac
(Prims.list (Prims.list FStar.Tactics.NamedView.binding * FStar.Tactics.NamedView.binding)) | {
"end_col": 18,
"end_line": 326,
"start_col": 15,
"start_line": 324
} |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.