file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Vale.AES.X64.AES256.fsti | Vale.AES.X64.AES256.va_wp_KeyExpansion256Stdcall | val va_wp_KeyExpansion256Stdcall
(win: bool)
(input_key_b output_key_expansion_b: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_KeyExpansion256Stdcall
(win: bool)
(input_key_b output_key_expansion_b: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_KeyExpansion256Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr input_key_b 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout
va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_rdx:nat64) (va_x_heap1:vale_heap)
(va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 4 va_x_xmm4
(va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_mem_heaplet 1
va_x_heap1 (va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0))))))) in va_get_ok va_sM /\
(let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx
va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet
0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128
(va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 2 (va_get_mem_layout va_sM) Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) key_expansion_ptr
output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64
rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _
-> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}j <= 14 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_256 key)
j)) ==> va_k va_sM (()))) | {
"file_name": "obj/Vale.AES.X64.AES256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 103,
"start_col": 0,
"start_line": 65
} | module Vale.AES.X64.AES256
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES256_helpers
open Vale.X64.CPU_Features_s
#reset-options "--z3rlimit 20"
//-- KeyExpansion256Stdcall
val va_code_KeyExpansion256Stdcall : win:bool -> Tot va_code
val va_codegen_success_KeyExpansion256Stdcall : win:bool -> Tot va_pbool
val va_lemma_KeyExpansion256Stdcall : va_b0:va_code -> va_s0:va_state -> win:bool ->
input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion256Stdcall win) va_s0 /\ va_get_ok va_s0
/\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr input_key_b 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout
va_s0) Secret)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM)
key_ptr input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout
va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then
va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in
let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}j <= 14 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_256 key)
j)) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64
rRdx va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.X64.AES256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
win: Prims.bool ->
input_key_b: Vale.X64.Memory.buffer128 ->
output_key_expansion_b: Vale.X64.Memory.buffer128 ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.X64.Memory.buffer128",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.aesni_enabled",
"Vale.X64.CPU_Features_s.avx_enabled",
"Vale.X64.CPU_Features_s.sse_enabled",
"Vale.X64.Decls.validSrcAddrs128",
"Vale.X64.Decls.va_get_mem_heaplet",
"Vale.X64.Decls.va_get_mem_layout",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.Decls.validDstAddrs128",
"FStar.Seq.Base.seq",
"Vale.Def.Words_s.nat32",
"Vale.AES.AES256_helpers.make_AES256_key",
"Vale.X64.Decls.buffer128_read",
"Vale.X64.Decls.va_int_range",
"Vale.X64.Decls.va_if",
"Vale.Def.Types_s.nat64",
"Vale.X64.Decls.va_get_reg64",
"Vale.X64.Machine_s.rRdx",
"Prims.l_not",
"Vale.X64.Machine_s.rRsi",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRdi",
"Prims.l_Forall",
"Vale.X64.InsBasic.vale_heap",
"Vale.X64.Memory.nat64",
"Vale.X64.Decls.quad32",
"Vale.X64.Flags.t",
"Prims.l_imp",
"Vale.X64.Decls.modifies_buffer128",
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Prims.eq2",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.index",
"Vale.AES.AES_s.key_to_round_keys_LE",
"Vale.AES.AES_common_s.AES_256",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_xmm",
"Vale.X64.Decls.va_upd_mem_heaplet",
"Vale.X64.Decls.va_upd_reg64",
"Vale.X64.Decls.va_upd_mem"
] | [] | false | false | false | true | true | let va_wp_KeyExpansion256Stdcall
(win: bool)
(input_key_b output_key_expansion_b: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\
(let key_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)
in
let key_expansion_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)
in
let key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32) =
Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b
0
(va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))
in
aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr
input_key_b
2
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0)
key_expansion_ptr
output_key_expansion_b
15
(va_get_mem_layout va_s0)
Secret) /\
(forall (va_x_mem: vale_heap)
(va_x_rdx: nat64)
(va_x_heap1: vale_heap)
(va_x_xmm1: quad32)
(va_x_xmm2: quad32)
(va_x_xmm3: quad32)
(va_x_xmm4: quad32)
(va_x_efl: Vale.X64.Flags.t).
let va_sM =
va_upd_flags va_x_efl
(va_upd_xmm 4
va_x_xmm4
(va_upd_xmm 3
va_x_xmm3
(va_upd_xmm 2
va_x_xmm2
(va_upd_xmm 1
va_x_xmm1
(va_upd_mem_heaplet 1
va_x_heap1
(va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0)))))))
in
va_get_ok va_sM /\
(let key_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)
in
let key_expansion_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)
in
let key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32) =
Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b
0
(va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))
in
aesni_enabled /\ avx_enabled /\ sse_enabled /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM)
key_ptr
input_key_b
2
(va_get_mem_layout va_sM)
Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM)
key_expansion_ptr
output_key_expansion_b
15
(va_get_mem_layout va_sM)
Secret) /\
(let key_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)
in
let key_expansion_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)
in
let key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32) =
Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b
0
(va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0))
in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b
(va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\
(forall (j: nat).
{:pattern (buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}
j <= 14 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_s.key_to_round_keys_LE AES_256 key)
j)) ==>
va_k va_sM (()))) | false |
Lib.IntTypes.fst | Lib.IntTypes.byte_to_int8 | val byte_to_int8 : x: FStar.UInt8.t -> b: FStar.Int8.t{FStar.Int8.v b = FStar.UInt8.v x @% Prims.pow2 8} | let byte_to_int8 x = Int.Cast.uint8_to_int8 x | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 76,
"start_col": 0,
"start_line": 76
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | x: FStar.UInt8.t -> b: FStar.Int8.t{FStar.Int8.v b = FStar.UInt8.v x @% Prims.pow2 8} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.t",
"FStar.Int.Cast.uint8_to_int8",
"FStar.Int8.t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"FStar.Int8.v",
"FStar.Int.Cast.op_At_Percent",
"FStar.UInt8.v",
"Prims.pow2"
] | [] | false | false | false | false | false | let byte_to_int8 x =
| Int.Cast.uint8_to_int8 x | false |
|
Spec.Exponentiation.fst | Spec.Exponentiation.exp_double_fw_lemma_loop | val exp_double_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma
(let acc = Loops.repeati i (exp_double_fw_f k a1 bBits b1 a2 b2 l) acc0 in
let accs = Loops.repeati i
(S.exp_double_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 l) (k.to.refl acc0) in
k.to.refl acc == accs) | val exp_double_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma
(let acc = Loops.repeati i (exp_double_fw_f k a1 bBits b1 a2 b2 l) acc0 in
let accs = Loops.repeati i
(S.exp_double_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 l) (k.to.refl acc0) in
k.to.refl acc == accs) | let rec exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 i =
let f0 = exp_double_fw_f k a1 bBits b1 a2 b2 l in
let f1 = S.exp_double_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 l in
if i = 0 then begin
Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0) end
else begin
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b1 l (i - 1) in
let bits_l2 = S.get_bits_l bBits b2 l (i - 1) in
exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a1 bits_l1;
pow_lemma k a2 bits_l2 end | {
"file_name": "specs/Spec.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 164,
"start_col": 0,
"start_line": 148
} | module Spec.Exponentiation
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
module S = Lib.Exponentiation
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 1"
val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in
let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in
k.to.refl acc == accs /\ k.to.refl c == cs)
let rec exp_rl_lemma_loop #t k a bBits b i =
let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a) in
let inp1 = (one, a) in
let f0 = S.exp_rl_f k.to.comm_monoid bBits b in
let f1 = exp_rl_f k bBits b in
if i = 0 then begin
Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1 end
else begin
exp_rl_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1) end
let exp_rl_lemma #t k a bBits b =
exp_rl_lemma_loop #t k a bBits b bBits
val exp_mont_ladder_swap_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (r0s, r1s, sws) =
Loops.repeati i (S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a, 0) in
let (r0, r1, sw) =
Loops.repeati i (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
k.to.refl r0 == r0s /\ k.to.refl r1 == r1s /\ sw == sws)
let rec exp_mont_ladder_swap_lemma_loop #t k a bBits b i =
let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a, 0) in
let inp1 = (one, a, 0) in
let f0 = S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b in
let f1 = exp_mont_ladder_swap_f k bBits b in
if i = 0 then begin
Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1 end
else begin
exp_mont_ladder_swap_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1) end
let exp_mont_ladder_swap_lemma #t k a bBits b =
exp_mont_ladder_swap_lemma_loop #t k a bBits b bBits
val exp_pow2_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> i:nat{i <= b} ->
Lemma (
let accs = Loops.repeat i (S.sqr k.to.comm_monoid) (k.to.refl a) in
let acc = Loops.repeat i k.sqr a in
k.to.refl acc == accs)
let rec exp_pow2_lemma_loop #t k a b i =
if i = 0 then begin
Loops.eq_repeat0 (S.sqr k.to.comm_monoid) (k.to.refl a);
Loops.eq_repeat0 k.sqr a end
else begin
exp_pow2_lemma_loop #t k a b (i - 1);
Loops.unfold_repeat b (S.sqr k.to.comm_monoid) (k.to.refl a) (i - 1);
Loops.unfold_repeat b k.sqr a (i - 1) end
let exp_pow2_lemma #t k a b =
exp_pow2_lemma_loop k a b b
#push-options "--fuel 1"
let pow_eq0 #t k a = ()
let pow_unfold #t k a i = ()
let rec pow_lemma #t k a b =
if b = 0 then ()
else pow_lemma k a (b - 1)
#pop-options
val exp_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma (
let acc = Loops.repeati i (exp_fw_f k a bBits b l) acc0 in
let accs = Loops.repeati i (S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l) (k.to.refl acc0) in
k.to.refl acc == accs)
let rec exp_fw_lemma_loop #t k a bBits b l acc0 i =
let f0 = exp_fw_f k a bBits b l in
let f1 = S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l in
if i = 0 then begin
Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0) end
else begin
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b l (i - 1) in
exp_fw_lemma_loop #t k a bBits b l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a bits_l1 end
let exp_fw_lemma #t k a bBits b l =
let acc0 =
if bBits % l = 0 then one ()
else begin
let bits_c = S.get_ith_lbits bBits b (bBits / l * l) l in
pow_lemma k a bits_c;
pow k a bits_c end in
exp_fw_lemma_loop #t k a bBits b l acc0 (bBits / l)
// Double exponentiation [a1^b1 `mul` a2^b2]
//-------------------------------------------
val exp_double_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma
(let acc = Loops.repeati i (exp_double_fw_f k a1 bBits b1 a2 b2 l) acc0 in
let accs = Loops.repeati i
(S.exp_double_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 l) (k.to.refl acc0) in
k.to.refl acc == accs) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Spec.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Spec.Exponentiation.concrete_ops t ->
a1: t ->
bBits: Prims.nat ->
b1: Prims.nat{b1 < Prims.pow2 bBits} ->
a2: t ->
b2: Prims.nat{b2 < Prims.pow2 bBits} ->
l: Prims.pos ->
acc0: t ->
i: Prims.nat{i <= bBits / l}
-> FStar.Pervasives.Lemma
(ensures
(let acc =
Lib.LoopCombinators.repeati i
(Spec.Exponentiation.exp_double_fw_f k a1 bBits b1 a2 b2 l)
acc0
in
let accs =
Lib.LoopCombinators.repeati i
(Lib.Exponentiation.exp_double_fw_f (Mkto_comm_monoid?.comm_monoid (Mkconcrete_ops?.to k
))
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a1)
bBits
b1
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a2)
b2
l)
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) acc0)
in
Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) acc == accs)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Exponentiation.concrete_ops",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Prims.op_LessThanOrEqual",
"Prims.op_Division",
"Prims.op_Equality",
"Prims.int",
"Lib.LoopCombinators.eq_repeati0",
"Spec.Exponentiation.__proj__Mkto_comm_monoid__item__a_spec",
"Spec.Exponentiation.__proj__Mkconcrete_ops__item__to",
"Spec.Exponentiation.__proj__Mkto_comm_monoid__item__refl",
"Prims.unit",
"Prims.bool",
"Spec.Exponentiation.pow_lemma",
"Spec.Exponentiation.exp_pow2_lemma",
"Lib.LoopCombinators.unfold_repeati",
"Prims.op_Subtraction",
"Spec.Exponentiation.exp_double_fw_lemma_loop",
"Lib.Exponentiation.get_bits_l",
"Lib.LoopCombinators.repeati",
"Lib.Exponentiation.exp_double_fw_f",
"Spec.Exponentiation.__proj__Mkto_comm_monoid__item__comm_monoid",
"Spec.Exponentiation.exp_double_fw_f"
] | [
"recursion"
] | false | false | true | false | false | let rec exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 i =
| let f0 = exp_double_fw_f k a1 bBits b1 a2 b2 l in
let f1 = S.exp_double_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 l in
if i = 0
then
(Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0))
else
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b1 l (i - 1) in
let bits_l2 = S.get_bits_l bBits b2 l (i - 1) in
exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a1 bits_l1;
pow_lemma k a2 bits_l2 | false |
Spec.Exponentiation.fst | Spec.Exponentiation.exp_fw_lemma | val exp_fw_lemma: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos ->
Lemma (k.to.refl (exp_fw k a bBits b l) == S.exp_fw k.to.comm_monoid (k.to.refl a) bBits b l) | val exp_fw_lemma: #t:Type -> k:concrete_ops t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos ->
Lemma (k.to.refl (exp_fw k a bBits b l) == S.exp_fw k.to.comm_monoid (k.to.refl a) bBits b l) | let exp_fw_lemma #t k a bBits b l =
let acc0 =
if bBits % l = 0 then one ()
else begin
let bits_c = S.get_ith_lbits bBits b (bBits / l * l) l in
pow_lemma k a bits_c;
pow k a bits_c end in
exp_fw_lemma_loop #t k a bBits b l acc0 (bBits / l) | {
"file_name": "specs/Spec.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 133,
"start_col": 0,
"start_line": 125
} | module Spec.Exponentiation
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
module S = Lib.Exponentiation
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 1"
val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in
let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in
k.to.refl acc == accs /\ k.to.refl c == cs)
let rec exp_rl_lemma_loop #t k a bBits b i =
let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a) in
let inp1 = (one, a) in
let f0 = S.exp_rl_f k.to.comm_monoid bBits b in
let f1 = exp_rl_f k bBits b in
if i = 0 then begin
Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1 end
else begin
exp_rl_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1) end
let exp_rl_lemma #t k a bBits b =
exp_rl_lemma_loop #t k a bBits b bBits
val exp_mont_ladder_swap_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (r0s, r1s, sws) =
Loops.repeati i (S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a, 0) in
let (r0, r1, sw) =
Loops.repeati i (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
k.to.refl r0 == r0s /\ k.to.refl r1 == r1s /\ sw == sws)
let rec exp_mont_ladder_swap_lemma_loop #t k a bBits b i =
let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a, 0) in
let inp1 = (one, a, 0) in
let f0 = S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b in
let f1 = exp_mont_ladder_swap_f k bBits b in
if i = 0 then begin
Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1 end
else begin
exp_mont_ladder_swap_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1) end
let exp_mont_ladder_swap_lemma #t k a bBits b =
exp_mont_ladder_swap_lemma_loop #t k a bBits b bBits
val exp_pow2_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> i:nat{i <= b} ->
Lemma (
let accs = Loops.repeat i (S.sqr k.to.comm_monoid) (k.to.refl a) in
let acc = Loops.repeat i k.sqr a in
k.to.refl acc == accs)
let rec exp_pow2_lemma_loop #t k a b i =
if i = 0 then begin
Loops.eq_repeat0 (S.sqr k.to.comm_monoid) (k.to.refl a);
Loops.eq_repeat0 k.sqr a end
else begin
exp_pow2_lemma_loop #t k a b (i - 1);
Loops.unfold_repeat b (S.sqr k.to.comm_monoid) (k.to.refl a) (i - 1);
Loops.unfold_repeat b k.sqr a (i - 1) end
let exp_pow2_lemma #t k a b =
exp_pow2_lemma_loop k a b b
#push-options "--fuel 1"
let pow_eq0 #t k a = ()
let pow_unfold #t k a i = ()
let rec pow_lemma #t k a b =
if b = 0 then ()
else pow_lemma k a (b - 1)
#pop-options
val exp_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma (
let acc = Loops.repeati i (exp_fw_f k a bBits b l) acc0 in
let accs = Loops.repeati i (S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l) (k.to.refl acc0) in
k.to.refl acc == accs)
let rec exp_fw_lemma_loop #t k a bBits b l acc0 i =
let f0 = exp_fw_f k a bBits b l in
let f1 = S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l in
if i = 0 then begin
Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0) end
else begin
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b l (i - 1) in
exp_fw_lemma_loop #t k a bBits b l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a bits_l1 end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Spec.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Spec.Exponentiation.concrete_ops t ->
a: t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
l: Prims.pos
-> FStar.Pervasives.Lemma
(ensures
Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) (Spec.Exponentiation.exp_fw k a bBits b l) ==
Lib.Exponentiation.exp_fw (Mkto_comm_monoid?.comm_monoid (Mkconcrete_ops?.to k))
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a)
bBits
b
l) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Exponentiation.concrete_ops",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Spec.Exponentiation.exp_fw_lemma_loop",
"Prims.op_Division",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Spec.Exponentiation.one",
"Prims.bool",
"Spec.Exponentiation.pow",
"Prims.unit",
"Spec.Exponentiation.pow_lemma",
"Lib.Exponentiation.get_ith_lbits",
"FStar.Mul.op_Star"
] | [] | false | false | true | false | false | let exp_fw_lemma #t k a bBits b l =
| let acc0 =
if bBits % l = 0
then one ()
else
let bits_c = S.get_ith_lbits bBits b ((bBits / l) * l) l in
pow_lemma k a bits_c;
pow k a bits_c
in
exp_fw_lemma_loop #t k a bBits b l acc0 (bBits / l) | false |
Spec.Exponentiation.fst | Spec.Exponentiation.exp_rl_lemma_loop | val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in
let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in
k.to.refl acc == accs /\ k.to.refl c == cs) | val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in
let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in
k.to.refl acc == accs /\ k.to.refl c == cs) | let rec exp_rl_lemma_loop #t k a bBits b i =
let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a) in
let inp1 = (one, a) in
let f0 = S.exp_rl_f k.to.comm_monoid bBits b in
let f1 = exp_rl_f k bBits b in
if i = 0 then begin
Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1 end
else begin
exp_rl_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1) end | {
"file_name": "specs/Spec.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 34,
"start_col": 0,
"start_line": 21
} | module Spec.Exponentiation
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
module S = Lib.Exponentiation
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 1"
val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in
let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in
k.to.refl acc == accs /\ k.to.refl c == cs) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Spec.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Spec.Exponentiation.concrete_ops t ->
a: t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
i: Prims.nat{i <= bBits}
-> FStar.Pervasives.Lemma
(ensures
(let one = Mkconcrete_ops?.one k () in
let _ =
Lib.LoopCombinators.repeati i
(Lib.Exponentiation.exp_rl_f (Mkto_comm_monoid?.comm_monoid (Mkconcrete_ops?.to k))
bBits
b)
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) one,
Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ accs cs = _ in
let _ = Lib.LoopCombinators.repeati i (Spec.Exponentiation.exp_rl_f k bBits b) (one, a) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ acc c = _ in
Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) acc == accs /\
Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) c == cs)
<:
Type0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Exponentiation.concrete_ops",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_LessThanOrEqual",
"Prims.op_Equality",
"Prims.int",
"Lib.LoopCombinators.eq_repeati0",
"FStar.Pervasives.Native.tuple2",
"Prims.unit",
"Spec.Exponentiation.__proj__Mkto_comm_monoid__item__a_spec",
"Spec.Exponentiation.__proj__Mkconcrete_ops__item__to",
"Prims.bool",
"Lib.LoopCombinators.unfold_repeati",
"Prims.op_Subtraction",
"Spec.Exponentiation.exp_rl_lemma_loop",
"Spec.Exponentiation.exp_rl_f",
"Lib.Exponentiation.exp_rl_f",
"Spec.Exponentiation.__proj__Mkto_comm_monoid__item__comm_monoid",
"FStar.Pervasives.Native.Mktuple2",
"Spec.Exponentiation.__proj__Mkto_comm_monoid__item__refl",
"Spec.Exponentiation.__proj__Mkconcrete_ops__item__one"
] | [
"recursion"
] | false | false | true | false | false | let rec exp_rl_lemma_loop #t k a bBits b i =
| let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a) in
let inp1 = (one, a) in
let f0 = S.exp_rl_f k.to.comm_monoid bBits b in
let f1 = exp_rl_f k bBits b in
if i = 0
then
(Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1)
else
(exp_rl_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1)) | false |
Lib.IntTypes.fst | Lib.IntTypes.op_At_Percent | val op_At_Percent : v: Prims.int -> p: Prims.int{p > 0 /\ p % 2 = 0} -> Prims.int | let op_At_Percent = Int.op_At_Percent | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 78,
"start_col": 0,
"start_line": 78
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | v: Prims.int -> p: Prims.int{p > 0 /\ p % 2 = 0} -> Prims.int | Prims.Tot | [
"total"
] | [] | [
"FStar.Int.op_At_Percent"
] | [] | false | false | false | false | false | let op_At_Percent =
| Int.op_At_Percent | false |
|
Spec.Exponentiation.fst | Spec.Exponentiation.exp_fw_lemma_loop | val exp_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma (
let acc = Loops.repeati i (exp_fw_f k a bBits b l) acc0 in
let accs = Loops.repeati i (S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l) (k.to.refl acc0) in
k.to.refl acc == accs) | val exp_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma (
let acc = Loops.repeati i (exp_fw_f k a bBits b l) acc0 in
let accs = Loops.repeati i (S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l) (k.to.refl acc0) in
k.to.refl acc == accs) | let rec exp_fw_lemma_loop #t k a bBits b l acc0 i =
let f0 = exp_fw_f k a bBits b l in
let f1 = S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l in
if i = 0 then begin
Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0) end
else begin
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b l (i - 1) in
exp_fw_lemma_loop #t k a bBits b l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a bits_l1 end | {
"file_name": "specs/Spec.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 122,
"start_col": 0,
"start_line": 108
} | module Spec.Exponentiation
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
module S = Lib.Exponentiation
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 1"
val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in
let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in
k.to.refl acc == accs /\ k.to.refl c == cs)
let rec exp_rl_lemma_loop #t k a bBits b i =
let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a) in
let inp1 = (one, a) in
let f0 = S.exp_rl_f k.to.comm_monoid bBits b in
let f1 = exp_rl_f k bBits b in
if i = 0 then begin
Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1 end
else begin
exp_rl_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1) end
let exp_rl_lemma #t k a bBits b =
exp_rl_lemma_loop #t k a bBits b bBits
val exp_mont_ladder_swap_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (r0s, r1s, sws) =
Loops.repeati i (S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a, 0) in
let (r0, r1, sw) =
Loops.repeati i (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
k.to.refl r0 == r0s /\ k.to.refl r1 == r1s /\ sw == sws)
let rec exp_mont_ladder_swap_lemma_loop #t k a bBits b i =
let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a, 0) in
let inp1 = (one, a, 0) in
let f0 = S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b in
let f1 = exp_mont_ladder_swap_f k bBits b in
if i = 0 then begin
Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1 end
else begin
exp_mont_ladder_swap_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1) end
let exp_mont_ladder_swap_lemma #t k a bBits b =
exp_mont_ladder_swap_lemma_loop #t k a bBits b bBits
val exp_pow2_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> i:nat{i <= b} ->
Lemma (
let accs = Loops.repeat i (S.sqr k.to.comm_monoid) (k.to.refl a) in
let acc = Loops.repeat i k.sqr a in
k.to.refl acc == accs)
let rec exp_pow2_lemma_loop #t k a b i =
if i = 0 then begin
Loops.eq_repeat0 (S.sqr k.to.comm_monoid) (k.to.refl a);
Loops.eq_repeat0 k.sqr a end
else begin
exp_pow2_lemma_loop #t k a b (i - 1);
Loops.unfold_repeat b (S.sqr k.to.comm_monoid) (k.to.refl a) (i - 1);
Loops.unfold_repeat b k.sqr a (i - 1) end
let exp_pow2_lemma #t k a b =
exp_pow2_lemma_loop k a b b
#push-options "--fuel 1"
let pow_eq0 #t k a = ()
let pow_unfold #t k a i = ()
let rec pow_lemma #t k a b =
if b = 0 then ()
else pow_lemma k a (b - 1)
#pop-options
val exp_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma (
let acc = Loops.repeati i (exp_fw_f k a bBits b l) acc0 in
let accs = Loops.repeati i (S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l) (k.to.refl acc0) in
k.to.refl acc == accs) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Spec.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Spec.Exponentiation.concrete_ops t ->
a: t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
l: Prims.pos ->
acc0: t ->
i: Prims.nat{i <= bBits / l}
-> FStar.Pervasives.Lemma
(ensures
(let acc = Lib.LoopCombinators.repeati i (Spec.Exponentiation.exp_fw_f k a bBits b l) acc0 in
let accs =
Lib.LoopCombinators.repeati i
(Lib.Exponentiation.exp_fw_f (Mkto_comm_monoid?.comm_monoid (Mkconcrete_ops?.to k))
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a)
bBits
b
l)
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) acc0)
in
Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) acc == accs)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Exponentiation.concrete_ops",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Prims.op_LessThanOrEqual",
"Prims.op_Division",
"Prims.op_Equality",
"Prims.int",
"Lib.LoopCombinators.eq_repeati0",
"Spec.Exponentiation.__proj__Mkto_comm_monoid__item__a_spec",
"Spec.Exponentiation.__proj__Mkconcrete_ops__item__to",
"Spec.Exponentiation.__proj__Mkto_comm_monoid__item__refl",
"Prims.unit",
"Prims.bool",
"Spec.Exponentiation.pow_lemma",
"Spec.Exponentiation.exp_pow2_lemma",
"Lib.LoopCombinators.unfold_repeati",
"Prims.op_Subtraction",
"Spec.Exponentiation.exp_fw_lemma_loop",
"Lib.Exponentiation.get_bits_l",
"Lib.LoopCombinators.repeati",
"Lib.Exponentiation.exp_fw_f",
"Spec.Exponentiation.__proj__Mkto_comm_monoid__item__comm_monoid",
"Spec.Exponentiation.exp_fw_f"
] | [
"recursion"
] | false | false | true | false | false | let rec exp_fw_lemma_loop #t k a bBits b l acc0 i =
| let f0 = exp_fw_f k a bBits b l in
let f1 = S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l in
if i = 0
then
(Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0))
else
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b l (i - 1) in
exp_fw_lemma_loop #t k a bBits b l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a bits_l1 | false |
Spec.Exponentiation.fst | Spec.Exponentiation.exp_four_fw_lemma | val exp_four_fw_lemma: #t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits}
-> a3:t -> b3:nat{b3 < pow2 bBits}
-> a4:t -> b4:nat{b4 < pow2 bBits}
-> l:pos ->
Lemma (k.to.refl (exp_four_fw k a1 bBits b1 a2 b2 a3 b3 a4 b4 l) ==
S.exp_four_fw k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2)
b2 (k.to.refl a3) b3 (k.to.refl a4) b4 l) | val exp_four_fw_lemma: #t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits}
-> a3:t -> b3:nat{b3 < pow2 bBits}
-> a4:t -> b4:nat{b4 < pow2 bBits}
-> l:pos ->
Lemma (k.to.refl (exp_four_fw k a1 bBits b1 a2 b2 a3 b3 a4 b4 l) ==
S.exp_four_fw k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2)
b2 (k.to.refl a3) b3 (k.to.refl a4) b4 l) | let exp_four_fw_lemma #t k a1 bBits b1 a2 b2 a3 b3 a4 b4 l =
let acc0 =
if bBits % l = 0 then one ()
else begin
let bits_c1 = S.get_ith_lbits bBits b1 (bBits / l * l) l in
let bits_c2 = S.get_ith_lbits bBits b2 (bBits / l * l) l in
let bits_c3 = S.get_ith_lbits bBits b3 (bBits / l * l) l in
let bits_c4 = S.get_ith_lbits bBits b4 (bBits / l * l) l in
let acc_a1 = pow k a1 bits_c1 in
let acc_a2 = pow k a2 bits_c2 in
let acc_a3 = pow k a3 bits_c3 in
let acc_a4 = pow k a4 bits_c4 in
pow_lemma k a1 bits_c1;
pow_lemma k a2 bits_c2;
pow_lemma k a3 bits_c3;
pow_lemma k a4 bits_c4;
let acc_a12 = k.mul acc_a1 acc_a2 in
let acc_a34 = k.mul acc_a3 acc_a4 in
let acc = k.mul acc_a12 acc_a34 in
acc end in
exp_four_fw_lemma_loop #t k a1 bBits b1 a2 b2 a3 b3 a4 b4 l acc0 (bBits / l) | {
"file_name": "specs/Spec.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 244,
"start_col": 0,
"start_line": 223
} | module Spec.Exponentiation
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
module S = Lib.Exponentiation
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 1"
val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in
let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in
k.to.refl acc == accs /\ k.to.refl c == cs)
let rec exp_rl_lemma_loop #t k a bBits b i =
let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a) in
let inp1 = (one, a) in
let f0 = S.exp_rl_f k.to.comm_monoid bBits b in
let f1 = exp_rl_f k bBits b in
if i = 0 then begin
Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1 end
else begin
exp_rl_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1) end
let exp_rl_lemma #t k a bBits b =
exp_rl_lemma_loop #t k a bBits b bBits
val exp_mont_ladder_swap_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (r0s, r1s, sws) =
Loops.repeati i (S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a, 0) in
let (r0, r1, sw) =
Loops.repeati i (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
k.to.refl r0 == r0s /\ k.to.refl r1 == r1s /\ sw == sws)
let rec exp_mont_ladder_swap_lemma_loop #t k a bBits b i =
let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a, 0) in
let inp1 = (one, a, 0) in
let f0 = S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b in
let f1 = exp_mont_ladder_swap_f k bBits b in
if i = 0 then begin
Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1 end
else begin
exp_mont_ladder_swap_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1) end
let exp_mont_ladder_swap_lemma #t k a bBits b =
exp_mont_ladder_swap_lemma_loop #t k a bBits b bBits
val exp_pow2_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> i:nat{i <= b} ->
Lemma (
let accs = Loops.repeat i (S.sqr k.to.comm_monoid) (k.to.refl a) in
let acc = Loops.repeat i k.sqr a in
k.to.refl acc == accs)
let rec exp_pow2_lemma_loop #t k a b i =
if i = 0 then begin
Loops.eq_repeat0 (S.sqr k.to.comm_monoid) (k.to.refl a);
Loops.eq_repeat0 k.sqr a end
else begin
exp_pow2_lemma_loop #t k a b (i - 1);
Loops.unfold_repeat b (S.sqr k.to.comm_monoid) (k.to.refl a) (i - 1);
Loops.unfold_repeat b k.sqr a (i - 1) end
let exp_pow2_lemma #t k a b =
exp_pow2_lemma_loop k a b b
#push-options "--fuel 1"
let pow_eq0 #t k a = ()
let pow_unfold #t k a i = ()
let rec pow_lemma #t k a b =
if b = 0 then ()
else pow_lemma k a (b - 1)
#pop-options
val exp_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma (
let acc = Loops.repeati i (exp_fw_f k a bBits b l) acc0 in
let accs = Loops.repeati i (S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l) (k.to.refl acc0) in
k.to.refl acc == accs)
let rec exp_fw_lemma_loop #t k a bBits b l acc0 i =
let f0 = exp_fw_f k a bBits b l in
let f1 = S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l in
if i = 0 then begin
Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0) end
else begin
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b l (i - 1) in
exp_fw_lemma_loop #t k a bBits b l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a bits_l1 end
let exp_fw_lemma #t k a bBits b l =
let acc0 =
if bBits % l = 0 then one ()
else begin
let bits_c = S.get_ith_lbits bBits b (bBits / l * l) l in
pow_lemma k a bits_c;
pow k a bits_c end in
exp_fw_lemma_loop #t k a bBits b l acc0 (bBits / l)
// Double exponentiation [a1^b1 `mul` a2^b2]
//-------------------------------------------
val exp_double_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma
(let acc = Loops.repeati i (exp_double_fw_f k a1 bBits b1 a2 b2 l) acc0 in
let accs = Loops.repeati i
(S.exp_double_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 l) (k.to.refl acc0) in
k.to.refl acc == accs)
let rec exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 i =
let f0 = exp_double_fw_f k a1 bBits b1 a2 b2 l in
let f1 = S.exp_double_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 l in
if i = 0 then begin
Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0) end
else begin
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b1 l (i - 1) in
let bits_l2 = S.get_bits_l bBits b2 l (i - 1) in
exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a1 bits_l1;
pow_lemma k a2 bits_l2 end
let exp_double_fw_lemma #t k a1 bBits b1 a2 b2 l =
let acc0 =
if bBits % l = 0 then one ()
else begin
let bits_c1 = S.get_ith_lbits bBits b1 (bBits / l * l) l in
let bits_c2 = S.get_ith_lbits bBits b2 (bBits / l * l) l in
let acc_a1 = pow k a1 bits_c1 in
let acc_a2 = pow k a2 bits_c2 in
pow_lemma k a1 bits_c1;
pow_lemma k a2 bits_c2;
k.mul acc_a1 acc_a2 end in
exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 (bBits / l)
// [a1^b1 `mul` a2^b2 `mul` a3^b3 `mul` a4^b4]
//----------------------------------------------
val exp_four_fw_lemma_loop:
#t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits}
-> a3:t -> b3:nat{b3 < pow2 bBits}
-> a4:t -> b4:nat{b4 < pow2 bBits}
-> l:pos -> acc0:t -> i:nat{i <= bBits / l} ->
Lemma
(let acc = Loops.repeati i (exp_four_fw_f k a1 bBits b1 a2 b2 a3 b3 a4 b4 l) acc0 in
let accs = Loops.repeati i
(S.exp_four_fw_f
k.to.comm_monoid (k.to.refl a1) bBits b1
(k.to.refl a2) b2 (k.to.refl a3) b3 (k.to.refl a4) b4 l) (k.to.refl acc0) in
k.to.refl acc == accs)
let rec exp_four_fw_lemma_loop #t k a1 bBits b1 a2 b2 a3 b3 a4 b4 l acc0 i =
let f0 = exp_four_fw_f k a1 bBits b1 a2 b2 a3 b3 a4 b4 l in
let f1 = S.exp_four_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1
(k.to.refl a2) b2 (k.to.refl a3) b3 (k.to.refl a4) b4 l in
if i = 0 then begin
Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0) end
else begin
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b1 l (i - 1) in
let bits_l2 = S.get_bits_l bBits b2 l (i - 1) in
let bits_l3 = S.get_bits_l bBits b3 l (i - 1) in
let bits_l4 = S.get_bits_l bBits b4 l (i - 1) in
exp_four_fw_lemma_loop #t k a1 bBits b1 a2 b2 a3 b3 a4 b4 l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a1 bits_l1;
pow_lemma k a2 bits_l2;
pow_lemma k a3 bits_l3;
pow_lemma k a4 bits_l4 end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Spec.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Spec.Exponentiation.concrete_ops t ->
a1: t ->
bBits: Prims.nat ->
b1: Prims.nat{b1 < Prims.pow2 bBits} ->
a2: t ->
b2: Prims.nat{b2 < Prims.pow2 bBits} ->
a3: t ->
b3: Prims.nat{b3 < Prims.pow2 bBits} ->
a4: t ->
b4: Prims.nat{b4 < Prims.pow2 bBits} ->
l: Prims.pos
-> FStar.Pervasives.Lemma
(ensures
Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k)
(Spec.Exponentiation.exp_four_fw k a1 bBits b1 a2 b2 a3 b3 a4 b4 l) ==
Lib.Exponentiation.exp_four_fw (Mkto_comm_monoid?.comm_monoid (Mkconcrete_ops?.to k))
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a1) bBits b1
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a2) b2
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a3) b3
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a4) b4 l) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Exponentiation.concrete_ops",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Spec.Exponentiation.exp_four_fw_lemma_loop",
"Prims.op_Division",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Spec.Exponentiation.one",
"Prims.bool",
"Spec.Exponentiation.__proj__Mkconcrete_ops__item__mul",
"Prims.unit",
"Spec.Exponentiation.pow_lemma",
"Spec.Exponentiation.pow",
"Lib.Exponentiation.get_ith_lbits",
"FStar.Mul.op_Star"
] | [] | false | false | true | false | false | let exp_four_fw_lemma #t k a1 bBits b1 a2 b2 a3 b3 a4 b4 l =
| let acc0 =
if bBits % l = 0
then one ()
else
let bits_c1 = S.get_ith_lbits bBits b1 ((bBits / l) * l) l in
let bits_c2 = S.get_ith_lbits bBits b2 ((bBits / l) * l) l in
let bits_c3 = S.get_ith_lbits bBits b3 ((bBits / l) * l) l in
let bits_c4 = S.get_ith_lbits bBits b4 ((bBits / l) * l) l in
let acc_a1 = pow k a1 bits_c1 in
let acc_a2 = pow k a2 bits_c2 in
let acc_a3 = pow k a3 bits_c3 in
let acc_a4 = pow k a4 bits_c4 in
pow_lemma k a1 bits_c1;
pow_lemma k a2 bits_c2;
pow_lemma k a3 bits_c3;
pow_lemma k a4 bits_c4;
let acc_a12 = k.mul acc_a1 acc_a2 in
let acc_a34 = k.mul acc_a3 acc_a4 in
let acc = k.mul acc_a12 acc_a34 in
acc
in
exp_four_fw_lemma_loop #t k a1 bBits b1 a2 b2 a3 b3 a4 b4 l acc0 (bBits / l) | false |
Vale.AES.X64.AES256.fsti | Vale.AES.X64.AES256.va_wp_AES256EncryptBlockStdcall | val va_wp_AES256EncryptBlockStdcall
(win: bool)
(input: quad32)
(key: (seq nat32))
(input_buffer output_buffer keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | val va_wp_AES256EncryptBlockStdcall
(win: bool)
(input: quad32)
(key: (seq nat32))
(input_buffer output_buffer keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 | let va_wp_AES256EncryptBlockStdcall (win:bool) (input:quad32) (key:(seq nat32))
(input_buffer:buffer128) (output_buffer:buffer128) (keys_buffer:buffer128) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (output_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (input_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (expanded_key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _
-> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0) in aesni_enabled /\ sse_enabled
/\ Vale.AES.AES_s.is_aes_key_LE AES_256 key /\ Vale.X64.Decls.buffer128_read input_buffer 0
(va_get_mem_heaplet 0 va_s0) == input /\ expanded_key_ptr == Vale.X64.Memory.buffer_addr
#Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) input_ptr input_buffer 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) output_ptr output_buffer 1 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) expanded_key_ptr keys_buffer 15
(va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==> Vale.X64.Decls.buffer128_read
keys_buffer i (va_get_mem_heaplet 0 va_s0) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_s.key_to_round_keys_LE AES_256 key) i)) /\ (forall (va_x_mem:vale_heap)
(va_x_r8:nat64) (va_x_heap1:vale_heap) (va_x_xmm0:quad32) (va_x_xmm2:quad32)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 0 va_x_xmm0 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rR8 va_x_r8 (va_upd_mem
va_x_mem va_s0))))) in va_get_ok va_sM /\ (let (output_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64
rRdi va_s0) in let (input_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let
(expanded_key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rR8
va_s0) (fun _ -> va_get_reg64 rRdx va_s0) in Vale.X64.Decls.modifies_mem
(Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 output_buffer) (va_get_mem_heaplet 1
va_s0) (va_get_mem_heaplet 1 va_sM) /\ Vale.X64.Decls.buffer128_read output_buffer 0
(va_get_mem_heaplet 1 va_sM) == Vale.AES.AES_s.aes_encrypt_LE AES_256 key input) ==> va_k va_sM
(()))) | {
"file_name": "obj/Vale.AES.X64.AES256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 240,
"start_col": 0,
"start_line": 210
} | module Vale.AES.X64.AES256
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES256_helpers
open Vale.X64.CPU_Features_s
#reset-options "--z3rlimit 20"
//-- KeyExpansion256Stdcall
val va_code_KeyExpansion256Stdcall : win:bool -> Tot va_code
val va_codegen_success_KeyExpansion256Stdcall : win:bool -> Tot va_pbool
val va_lemma_KeyExpansion256Stdcall : va_b0:va_code -> va_s0:va_state -> win:bool ->
input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion256Stdcall win) va_s0 /\ va_get_ok va_s0
/\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr input_key_b 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout
va_s0) Secret)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM)
key_ptr input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout
va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then
va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in
let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}j <= 14 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_256 key)
j)) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64
rRdx va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))
[@ va_qattr]
let va_wp_KeyExpansion256Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr input_key_b 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout
va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_rdx:nat64) (va_x_heap1:vale_heap)
(va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 4 va_x_xmm4
(va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_mem_heaplet 1
va_x_heap1 (va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0))))))) in va_get_ok va_sM /\
(let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx
va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet
0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128
(va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 2 (va_get_mem_layout va_sM) Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) key_expansion_ptr
output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64
rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _
-> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}j <= 14 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_256 key)
j)) ==> va_k va_sM (())))
val va_wpProof_KeyExpansion256Stdcall : win:bool -> input_key_b:buffer128 ->
output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_KeyExpansion256Stdcall win input_key_b
output_key_expansion_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion256Stdcall win)
([va_Mod_flags; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1;
va_Mod_reg64 rRdx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_KeyExpansion256Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion256Stdcall win)) =
(va_QProc (va_code_KeyExpansion256Stdcall win) ([va_Mod_flags; va_Mod_xmm 4; va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem])
(va_wp_KeyExpansion256Stdcall win input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion256Stdcall win input_key_b output_key_expansion_b))
//--
//-- AES256EncryptBlock
val va_code_AES256EncryptBlock : va_dummy:unit -> Tot va_code
val va_codegen_success_AES256EncryptBlock : va_dummy:unit -> Tot va_pbool
val va_lemma_AES256EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq
nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES256EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\
(aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_256 key /\
FStar.Seq.Base.length #quad32 round_keys == 15 /\ round_keys ==
Vale.AES.AES_s.key_to_round_keys_LE AES_256 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64
rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg64 rR8 va_s0) keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i
< 15 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #quad32 round_keys i)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_xmm 0 va_sM == Vale.AES.AES_s.aes_encrypt_LE AES_256 key input /\ va_state_eq va_sM
(va_update_flags va_sM (va_update_xmm 2 va_sM (va_update_xmm 0 va_sM (va_update_ok va_sM
va_s0))))))
[@ va_qattr]
let va_wp_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_256 key /\
FStar.Seq.Base.length #quad32 round_keys == 15 /\ round_keys ==
Vale.AES.AES_s.key_to_round_keys_LE AES_256 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64
rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg64 rR8 va_s0) keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i
< 15 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_xmm0:quad32) (va_x_xmm2:quad32)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 0 va_x_xmm0 va_s0)) in va_get_ok va_sM /\ va_get_xmm 0 va_sM ==
Vale.AES.AES_s.aes_encrypt_LE AES_256 key input ==> va_k va_sM (())))
val va_wpProof_AES256EncryptBlock : input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) ->
keys_buffer:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_AES256EncryptBlock input key round_keys keys_buffer va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES256EncryptBlock ()) ([va_Mod_flags;
va_Mod_xmm 2; va_Mod_xmm 0]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) : (va_quickCode unit (va_code_AES256EncryptBlock ())) =
(va_QProc (va_code_AES256EncryptBlock ()) ([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0])
(va_wp_AES256EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES256EncryptBlock
input key round_keys keys_buffer))
//--
//-- AES256EncryptBlockStdcall
val va_code_AES256EncryptBlockStdcall : win:bool -> Tot va_code
val va_codegen_success_AES256EncryptBlockStdcall : win:bool -> Tot va_pbool
val va_lemma_AES256EncryptBlockStdcall : va_b0:va_code -> va_s0:va_state -> win:bool ->
input:quad32 -> key:(seq nat32) -> input_buffer:buffer128 -> output_buffer:buffer128 ->
keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES256EncryptBlockStdcall win) va_s0 /\ va_get_ok
va_s0 /\ (let (output_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64
rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (input_ptr:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in
let (expanded_key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR8
va_s0 else va_get_reg64 rRdx va_s0) in aesni_enabled /\ sse_enabled /\
Vale.AES.AES_s.is_aes_key_LE AES_256 key /\ Vale.X64.Decls.buffer128_read input_buffer 0
(va_get_mem_heaplet 0 va_s0) == input /\ expanded_key_ptr == Vale.X64.Memory.buffer_addr
#Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) input_ptr input_buffer 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) output_ptr output_buffer 1 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) expanded_key_ptr keys_buffer 15
(va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==> Vale.X64.Decls.buffer128_read
keys_buffer i (va_get_mem_heaplet 0 va_s0) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_s.key_to_round_keys_LE AES_256 key) i))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (output_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (input_ptr:(va_int_range 0 18446744073709551615)) = (if
win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(expanded_key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR8 va_s0
else va_get_reg64 rRdx va_s0) in Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer
#Vale.X64.Memory.vuint128 output_buffer) (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1
va_sM) /\ Vale.X64.Decls.buffer128_read output_buffer 0 (va_get_mem_heaplet 1 va_sM) ==
Vale.AES.AES_s.aes_encrypt_LE AES_256 key input) /\ va_state_eq va_sM (va_update_flags va_sM
(va_update_xmm 2 va_sM (va_update_xmm 0 va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64
rR8 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0))))))))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.X64.AES256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
win: Prims.bool ->
input: Vale.X64.Decls.quad32 ->
key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 ->
input_buffer: Vale.X64.Memory.buffer128 ->
output_buffer: Vale.X64.Memory.buffer128 ->
keys_buffer: Vale.X64.Memory.buffer128 ->
va_s0: Vale.X64.Decls.va_state ->
va_k: (_: Vale.X64.Decls.va_state -> _: Prims.unit -> Type0)
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.X64.Decls.quad32",
"FStar.Seq.Base.seq",
"Vale.X64.Memory.nat32",
"Vale.X64.Memory.buffer128",
"Vale.X64.Decls.va_state",
"Prims.unit",
"Prims.l_and",
"Prims.b2t",
"Vale.X64.Decls.va_get_ok",
"Vale.X64.CPU_Features_s.aesni_enabled",
"Vale.X64.CPU_Features_s.sse_enabled",
"Vale.AES.AES_s.is_aes_key_LE",
"Vale.AES.AES_common_s.AES_256",
"Prims.eq2",
"Vale.X64.Decls.buffer128_read",
"Vale.X64.Decls.va_get_mem_heaplet",
"Prims.int",
"Vale.X64.Memory.buffer_addr",
"Vale.X64.Memory.vuint128",
"Vale.X64.Decls.validSrcAddrs128",
"Vale.X64.Decls.va_get_mem_layout",
"Vale.Arch.HeapTypes_s.Secret",
"Vale.X64.Decls.validDstAddrs128",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.op_LessThan",
"Vale.Def.Types_s.quad32",
"FStar.Seq.Base.index",
"Vale.AES.AES_s.key_to_round_keys_LE",
"Vale.X64.Decls.va_int_range",
"Vale.X64.Decls.va_if",
"Vale.Def.Types_s.nat64",
"Vale.X64.Decls.va_get_reg64",
"Vale.X64.Machine_s.rR8",
"Prims.l_not",
"Vale.X64.Machine_s.rRdx",
"Vale.X64.Machine_s.rRsi",
"Vale.X64.Machine_s.rRcx",
"Vale.X64.Machine_s.rRdi",
"Vale.X64.InsBasic.vale_heap",
"Vale.X64.Memory.nat64",
"Vale.X64.Flags.t",
"Vale.X64.Decls.modifies_mem",
"Vale.X64.Decls.loc_buffer",
"Vale.AES.AES_s.aes_encrypt_LE",
"Vale.X64.State.vale_state",
"Vale.X64.Decls.va_upd_flags",
"Vale.X64.Decls.va_upd_xmm",
"Vale.X64.Decls.va_upd_mem_heaplet",
"Vale.X64.Decls.va_upd_reg64",
"Vale.X64.Decls.va_upd_mem"
] | [] | false | false | false | true | true | let va_wp_AES256EncryptBlockStdcall
(win: bool)
(input: quad32)
(key: (seq nat32))
(input_buffer output_buffer keys_buffer: buffer128)
(va_s0: va_state)
(va_k: (va_state -> unit -> Type0))
: Type0 =
| (va_get_ok va_s0 /\
(let output_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)
in
let input_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)
in
let expanded_key_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0)
in
aesni_enabled /\ sse_enabled /\ Vale.AES.AES_s.is_aes_key_LE AES_256 key /\
Vale.X64.Decls.buffer128_read input_buffer 0 (va_get_mem_heaplet 0 va_s0) == input /\
expanded_key_ptr ==
Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
input_ptr
input_buffer
1
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_s0)
output_ptr
output_buffer
1
(va_get_mem_layout va_s0)
Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
expanded_key_ptr
keys_buffer
15
(va_get_mem_layout va_s0)
Secret /\
(forall (i: nat).
i < 15 ==>
Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_s.key_to_round_keys_LE AES_256 key)
i)) /\
(forall (va_x_mem: vale_heap)
(va_x_r8: nat64)
(va_x_heap1: vale_heap)
(va_x_xmm0: quad32)
(va_x_xmm2: quad32)
(va_x_efl: Vale.X64.Flags.t).
let va_sM =
va_upd_flags va_x_efl
(va_upd_xmm 2
va_x_xmm2
(va_upd_xmm 0
va_x_xmm0
(va_upd_mem_heaplet 1
va_x_heap1
(va_upd_reg64 rR8 va_x_r8 (va_upd_mem va_x_mem va_s0)))))
in
va_get_ok va_sM /\
(let output_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0)
in
let input_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0)
in
let expanded_key_ptr:(va_int_range 0 18446744073709551615) =
va_if win (fun _ -> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0)
in
Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128
output_buffer)
(va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\
Vale.X64.Decls.buffer128_read output_buffer 0 (va_get_mem_heaplet 1 va_sM) ==
Vale.AES.AES_s.aes_encrypt_LE AES_256 key input) ==>
va_k va_sM (()))) | false |
Vale.AES.X64.AES256.fsti | Vale.AES.X64.AES256.va_quick_AES256EncryptBlockStdcall | val va_quick_AES256EncryptBlockStdcall
(win: bool)
(input: quad32)
(key: (seq nat32))
(input_buffer output_buffer keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES256EncryptBlockStdcall win)) | val va_quick_AES256EncryptBlockStdcall
(win: bool)
(input: quad32)
(key: (seq nat32))
(input_buffer output_buffer keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES256EncryptBlockStdcall win)) | let va_quick_AES256EncryptBlockStdcall (win:bool) (input:quad32) (key:(seq nat32))
(input_buffer:buffer128) (output_buffer:buffer128) (keys_buffer:buffer128) : (va_quickCode unit
(va_code_AES256EncryptBlockStdcall win)) =
(va_QProc (va_code_AES256EncryptBlockStdcall win) ([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0;
va_Mod_mem_heaplet 1; va_Mod_reg64 rR8; va_Mod_mem]) (va_wp_AES256EncryptBlockStdcall win input
key input_buffer output_buffer keys_buffer) (va_wpProof_AES256EncryptBlockStdcall win input key
input_buffer output_buffer keys_buffer)) | {
"file_name": "obj/Vale.AES.X64.AES256.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 258,
"start_col": 0,
"start_line": 252
} | module Vale.AES.X64.AES256
open Vale.Def.Opaque_s
open Vale.Def.Types_s
open FStar.Seq
open Vale.AES.AES_s
open Vale.X64.Machine_s
open Vale.X64.Memory
open Vale.X64.State
open Vale.X64.Decls
open Vale.X64.InsBasic
open Vale.X64.InsMem
open Vale.X64.InsVector
open Vale.X64.InsAes
open Vale.X64.QuickCode
open Vale.X64.QuickCodes
open Vale.Arch.Types
open Vale.AES.AES256_helpers
open Vale.X64.CPU_Features_s
#reset-options "--z3rlimit 20"
//-- KeyExpansion256Stdcall
val va_code_KeyExpansion256Stdcall : win:bool -> Tot va_code
val va_codegen_success_KeyExpansion256Stdcall : win:bool -> Tot va_pbool
val va_lemma_KeyExpansion256Stdcall : va_b0:va_code -> va_s0:va_state -> win:bool ->
input_key_b:buffer128 -> output_key_expansion_b:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_KeyExpansion256Stdcall win) va_s0 /\ va_get_ok va_s0
/\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr input_key_b 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout
va_s0) Secret)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615))
= (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_sM)
key_ptr input_key_b 2 (va_get_mem_layout va_sM) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_sM) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout
va_sM) Secret) /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = (if win then
va_get_reg64 rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in
let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}j <= 14 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_256 key)
j)) /\ va_state_eq va_sM (va_update_flags va_sM (va_update_xmm 4 va_sM (va_update_xmm 3 va_sM
(va_update_xmm 2 va_sM (va_update_xmm 1 va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64
rRdx va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))))
[@ va_qattr]
let va_wp_KeyExpansion256Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let
(key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64
rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in aesni_enabled /\
avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
key_ptr input_key_b 2 (va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128
(va_get_mem_heaplet 1 va_s0) key_expansion_ptr output_key_expansion_b 15 (va_get_mem_layout
va_s0) Secret) /\ (forall (va_x_mem:vale_heap) (va_x_rdx:nat64) (va_x_heap1:vale_heap)
(va_x_xmm1:quad32) (va_x_xmm2:quad32) (va_x_xmm3:quad32) (va_x_xmm4:quad32)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 4 va_x_xmm4
(va_upd_xmm 3 va_x_xmm3 (va_upd_xmm 2 va_x_xmm2 (va_upd_xmm 1 va_x_xmm1 (va_upd_mem_heaplet 1
va_x_heap1 (va_upd_reg64 rRdx va_x_rdx (va_upd_mem va_x_mem va_s0))))))) in va_get_ok va_sM /\
(let (key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx
va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (key:(FStar.Seq.Base.seq Vale.Def.Types_s.nat32)) =
Vale.AES.AES256_helpers.make_AES256_key (Vale.X64.Decls.buffer128_read input_key_b 0
(va_get_mem_heaplet 0 va_s0)) (Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet
0 va_s0)) in aesni_enabled /\ avx_enabled /\ sse_enabled /\ Vale.X64.Decls.validSrcAddrs128
(va_get_mem_heaplet 0 va_sM) key_ptr input_key_b 2 (va_get_mem_layout va_sM) Secret /\
Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1 va_sM) key_expansion_ptr
output_key_expansion_b 15 (va_get_mem_layout va_sM) Secret) /\ (let (key_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64
rRdi va_s0) in let (key_expansion_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _
-> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let (key:(FStar.Seq.Base.seq
Vale.Def.Types_s.nat32)) = Vale.AES.AES256_helpers.make_AES256_key
(Vale.X64.Decls.buffer128_read input_key_b 0 (va_get_mem_heaplet 0 va_s0))
(Vale.X64.Decls.buffer128_read input_key_b 1 (va_get_mem_heaplet 0 va_s0)) in
Vale.X64.Decls.modifies_buffer128 output_key_expansion_b (va_get_mem_heaplet 1 va_s0)
(va_get_mem_heaplet 1 va_sM) /\ (forall (j:nat) . {:pattern(buffer128_read
output_key_expansion_b j (va_get_mem_heaplet 1 va_sM))}j <= 14 ==>
Vale.X64.Decls.buffer128_read output_key_expansion_b j (va_get_mem_heaplet 1 va_sM) ==
FStar.Seq.Base.index #Vale.Def.Types_s.quad32 (Vale.AES.AES_s.key_to_round_keys_LE AES_256 key)
j)) ==> va_k va_sM (())))
val va_wpProof_KeyExpansion256Stdcall : win:bool -> input_key_b:buffer128 ->
output_key_expansion_b:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_KeyExpansion256Stdcall win input_key_b
output_key_expansion_b va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_KeyExpansion256Stdcall win)
([va_Mod_flags; va_Mod_xmm 4; va_Mod_xmm 3; va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1;
va_Mod_reg64 rRdx; va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_KeyExpansion256Stdcall (win:bool) (input_key_b:buffer128)
(output_key_expansion_b:buffer128) : (va_quickCode unit (va_code_KeyExpansion256Stdcall win)) =
(va_QProc (va_code_KeyExpansion256Stdcall win) ([va_Mod_flags; va_Mod_xmm 4; va_Mod_xmm 3;
va_Mod_xmm 2; va_Mod_xmm 1; va_Mod_mem_heaplet 1; va_Mod_reg64 rRdx; va_Mod_mem])
(va_wp_KeyExpansion256Stdcall win input_key_b output_key_expansion_b)
(va_wpProof_KeyExpansion256Stdcall win input_key_b output_key_expansion_b))
//--
//-- AES256EncryptBlock
val va_code_AES256EncryptBlock : va_dummy:unit -> Tot va_code
val va_codegen_success_AES256EncryptBlock : va_dummy:unit -> Tot va_pbool
val va_lemma_AES256EncryptBlock : va_b0:va_code -> va_s0:va_state -> input:quad32 -> key:(seq
nat32) -> round_keys:(seq quad32) -> keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES256EncryptBlock ()) va_s0 /\ va_get_ok va_s0 /\
(aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_256 key /\
FStar.Seq.Base.length #quad32 round_keys == 15 /\ round_keys ==
Vale.AES.AES_s.key_to_round_keys_LE AES_256 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64
rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg64 rR8 va_s0) keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i
< 15 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #quad32 round_keys i)))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
va_get_xmm 0 va_sM == Vale.AES.AES_s.aes_encrypt_LE AES_256 key input /\ va_state_eq va_sM
(va_update_flags va_sM (va_update_xmm 2 va_sM (va_update_xmm 0 va_sM (va_update_ok va_sM
va_s0))))))
[@ va_qattr]
let va_wp_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) (va_s0:va_state) (va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (aesni_enabled /\ sse_enabled) /\ Vale.AES.AES_s.is_aes_key_LE AES_256 key /\
FStar.Seq.Base.length #quad32 round_keys == 15 /\ round_keys ==
Vale.AES.AES_s.key_to_round_keys_LE AES_256 key /\ va_get_xmm 0 va_s0 == input /\ va_get_reg64
rR8 va_s0 == Vale.X64.Memory.buffer_addr #Vale.X64.Memory.vuint128 keys_buffer
(va_get_mem_heaplet 0 va_s0) /\ Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0)
(va_get_reg64 rR8 va_s0) keys_buffer 15 (va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i
< 15 ==> Vale.X64.Decls.buffer128_read keys_buffer i (va_get_mem_heaplet 0 va_s0) ==
FStar.Seq.Base.index #quad32 round_keys i) /\ (forall (va_x_xmm0:quad32) (va_x_xmm2:quad32)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 0 va_x_xmm0 va_s0)) in va_get_ok va_sM /\ va_get_xmm 0 va_sM ==
Vale.AES.AES_s.aes_encrypt_LE AES_256 key input ==> va_k va_sM (())))
val va_wpProof_AES256EncryptBlock : input:quad32 -> key:(seq nat32) -> round_keys:(seq quad32) ->
keys_buffer:buffer128 -> va_s0:va_state -> va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_AES256EncryptBlock input key round_keys keys_buffer va_s0
va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES256EncryptBlock ()) ([va_Mod_flags;
va_Mod_xmm 2; va_Mod_xmm 0]) va_s0 va_k ((va_sM, va_f0, va_g))))
[@ "opaque_to_smt" va_qattr]
let va_quick_AES256EncryptBlock (input:quad32) (key:(seq nat32)) (round_keys:(seq quad32))
(keys_buffer:buffer128) : (va_quickCode unit (va_code_AES256EncryptBlock ())) =
(va_QProc (va_code_AES256EncryptBlock ()) ([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0])
(va_wp_AES256EncryptBlock input key round_keys keys_buffer) (va_wpProof_AES256EncryptBlock
input key round_keys keys_buffer))
//--
//-- AES256EncryptBlockStdcall
val va_code_AES256EncryptBlockStdcall : win:bool -> Tot va_code
val va_codegen_success_AES256EncryptBlockStdcall : win:bool -> Tot va_pbool
val va_lemma_AES256EncryptBlockStdcall : va_b0:va_code -> va_s0:va_state -> win:bool ->
input:quad32 -> key:(seq nat32) -> input_buffer:buffer128 -> output_buffer:buffer128 ->
keys_buffer:buffer128
-> Ghost (va_state & va_fuel)
(requires (va_require_total va_b0 (va_code_AES256EncryptBlockStdcall win) va_s0 /\ va_get_ok
va_s0 /\ (let (output_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64
rRcx va_s0 else va_get_reg64 rRdi va_s0) in let (input_ptr:(va_int_range 0
18446744073709551615)) = (if win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in
let (expanded_key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR8
va_s0 else va_get_reg64 rRdx va_s0) in aesni_enabled /\ sse_enabled /\
Vale.AES.AES_s.is_aes_key_LE AES_256 key /\ Vale.X64.Decls.buffer128_read input_buffer 0
(va_get_mem_heaplet 0 va_s0) == input /\ expanded_key_ptr == Vale.X64.Memory.buffer_addr
#Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) input_ptr input_buffer 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) output_ptr output_buffer 1 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) expanded_key_ptr keys_buffer 15
(va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==> Vale.X64.Decls.buffer128_read
keys_buffer i (va_get_mem_heaplet 0 va_s0) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_s.key_to_round_keys_LE AES_256 key) i))))
(ensures (fun (va_sM, va_fM) -> va_ensure_total va_b0 va_s0 va_sM va_fM /\ va_get_ok va_sM /\
(let (output_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rRcx va_s0
else va_get_reg64 rRdi va_s0) in let (input_ptr:(va_int_range 0 18446744073709551615)) = (if
win then va_get_reg64 rRdx va_s0 else va_get_reg64 rRsi va_s0) in let
(expanded_key_ptr:(va_int_range 0 18446744073709551615)) = (if win then va_get_reg64 rR8 va_s0
else va_get_reg64 rRdx va_s0) in Vale.X64.Decls.modifies_mem (Vale.X64.Decls.loc_buffer
#Vale.X64.Memory.vuint128 output_buffer) (va_get_mem_heaplet 1 va_s0) (va_get_mem_heaplet 1
va_sM) /\ Vale.X64.Decls.buffer128_read output_buffer 0 (va_get_mem_heaplet 1 va_sM) ==
Vale.AES.AES_s.aes_encrypt_LE AES_256 key input) /\ va_state_eq va_sM (va_update_flags va_sM
(va_update_xmm 2 va_sM (va_update_xmm 0 va_sM (va_update_mem_heaplet 1 va_sM (va_update_reg64
rR8 va_sM (va_update_ok va_sM (va_update_mem va_sM va_s0)))))))))
[@ va_qattr]
let va_wp_AES256EncryptBlockStdcall (win:bool) (input:quad32) (key:(seq nat32))
(input_buffer:buffer128) (output_buffer:buffer128) (keys_buffer:buffer128) (va_s0:va_state)
(va_k:(va_state -> unit -> Type0)) : Type0 =
(va_get_ok va_s0 /\ (let (output_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64 rRdi va_s0) in let (input_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64
rRsi va_s0) in let (expanded_key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _
-> va_get_reg64 rR8 va_s0) (fun _ -> va_get_reg64 rRdx va_s0) in aesni_enabled /\ sse_enabled
/\ Vale.AES.AES_s.is_aes_key_LE AES_256 key /\ Vale.X64.Decls.buffer128_read input_buffer 0
(va_get_mem_heaplet 0 va_s0) == input /\ expanded_key_ptr == Vale.X64.Memory.buffer_addr
#Vale.X64.Memory.vuint128 keys_buffer (va_get_mem_heaplet 0 va_s0) /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) input_ptr input_buffer 1
(va_get_mem_layout va_s0) Secret /\ Vale.X64.Decls.validDstAddrs128 (va_get_mem_heaplet 1
va_s0) output_ptr output_buffer 1 (va_get_mem_layout va_s0) Secret /\
Vale.X64.Decls.validSrcAddrs128 (va_get_mem_heaplet 0 va_s0) expanded_key_ptr keys_buffer 15
(va_get_mem_layout va_s0) Secret /\ (forall (i:nat) . i < 15 ==> Vale.X64.Decls.buffer128_read
keys_buffer i (va_get_mem_heaplet 0 va_s0) == FStar.Seq.Base.index #Vale.Def.Types_s.quad32
(Vale.AES.AES_s.key_to_round_keys_LE AES_256 key) i)) /\ (forall (va_x_mem:vale_heap)
(va_x_r8:nat64) (va_x_heap1:vale_heap) (va_x_xmm0:quad32) (va_x_xmm2:quad32)
(va_x_efl:Vale.X64.Flags.t) . let va_sM = va_upd_flags va_x_efl (va_upd_xmm 2 va_x_xmm2
(va_upd_xmm 0 va_x_xmm0 (va_upd_mem_heaplet 1 va_x_heap1 (va_upd_reg64 rR8 va_x_r8 (va_upd_mem
va_x_mem va_s0))))) in va_get_ok va_sM /\ (let (output_ptr:(va_int_range 0
18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rRcx va_s0) (fun _ -> va_get_reg64
rRdi va_s0) in let (input_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ ->
va_get_reg64 rRdx va_s0) (fun _ -> va_get_reg64 rRsi va_s0) in let
(expanded_key_ptr:(va_int_range 0 18446744073709551615)) = va_if win (fun _ -> va_get_reg64 rR8
va_s0) (fun _ -> va_get_reg64 rRdx va_s0) in Vale.X64.Decls.modifies_mem
(Vale.X64.Decls.loc_buffer #Vale.X64.Memory.vuint128 output_buffer) (va_get_mem_heaplet 1
va_s0) (va_get_mem_heaplet 1 va_sM) /\ Vale.X64.Decls.buffer128_read output_buffer 0
(va_get_mem_heaplet 1 va_sM) == Vale.AES.AES_s.aes_encrypt_LE AES_256 key input) ==> va_k va_sM
(())))
val va_wpProof_AES256EncryptBlockStdcall : win:bool -> input:quad32 -> key:(seq nat32) ->
input_buffer:buffer128 -> output_buffer:buffer128 -> keys_buffer:buffer128 -> va_s0:va_state ->
va_k:(va_state -> unit -> Type0)
-> Ghost (va_state & va_fuel & unit)
(requires (va_t_require va_s0 /\ va_wp_AES256EncryptBlockStdcall win input key input_buffer
output_buffer keys_buffer va_s0 va_k))
(ensures (fun (va_sM, va_f0, va_g) -> va_t_ensure (va_code_AES256EncryptBlockStdcall win)
([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0; va_Mod_mem_heaplet 1; va_Mod_reg64 rR8;
va_Mod_mem]) va_s0 va_k ((va_sM, va_f0, va_g)))) | {
"checked_file": "/",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.QuickCodes.fsti.checked",
"Vale.X64.QuickCode.fst.checked",
"Vale.X64.Memory.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.InsVector.fsti.checked",
"Vale.X64.InsMem.fsti.checked",
"Vale.X64.InsBasic.fsti.checked",
"Vale.X64.InsAes.fsti.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.Def.Opaque_s.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"Vale.AES.AES256_helpers.fsti.checked",
"prims.fst.checked",
"FStar.Seq.Base.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.AES.X64.AES256.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES256_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCodes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.QuickCode",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsAes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsMem",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.InsBasic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.State",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Opaque_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
win: Prims.bool ->
input: Vale.X64.Decls.quad32 ->
key: FStar.Seq.Base.seq Vale.X64.Memory.nat32 ->
input_buffer: Vale.X64.Memory.buffer128 ->
output_buffer: Vale.X64.Memory.buffer128 ->
keys_buffer: Vale.X64.Memory.buffer128
-> Vale.X64.QuickCode.va_quickCode Prims.unit
(Vale.AES.X64.AES256.va_code_AES256EncryptBlockStdcall win) | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"Vale.X64.Decls.quad32",
"FStar.Seq.Base.seq",
"Vale.X64.Memory.nat32",
"Vale.X64.Memory.buffer128",
"Vale.X64.QuickCode.va_QProc",
"Prims.unit",
"Vale.AES.X64.AES256.va_code_AES256EncryptBlockStdcall",
"Prims.Cons",
"Vale.X64.QuickCode.mod_t",
"Vale.X64.QuickCode.va_Mod_flags",
"Vale.X64.QuickCode.va_Mod_xmm",
"Vale.X64.QuickCode.va_Mod_mem_heaplet",
"Vale.X64.QuickCode.va_Mod_reg64",
"Vale.X64.Machine_s.rR8",
"Vale.X64.QuickCode.va_Mod_mem",
"Prims.Nil",
"Vale.AES.X64.AES256.va_wp_AES256EncryptBlockStdcall",
"Vale.AES.X64.AES256.va_wpProof_AES256EncryptBlockStdcall",
"Vale.X64.QuickCode.va_quickCode"
] | [] | false | false | false | false | false | let va_quick_AES256EncryptBlockStdcall
(win: bool)
(input: quad32)
(key: (seq nat32))
(input_buffer output_buffer keys_buffer: buffer128)
: (va_quickCode unit (va_code_AES256EncryptBlockStdcall win)) =
| (va_QProc (va_code_AES256EncryptBlockStdcall win)
([va_Mod_flags; va_Mod_xmm 2; va_Mod_xmm 0; va_Mod_mem_heaplet 1; va_Mod_reg64 rR8; va_Mod_mem])
(va_wp_AES256EncryptBlockStdcall win input key input_buffer output_buffer keys_buffer)
(va_wpProof_AES256EncryptBlockStdcall win input key input_buffer output_buffer keys_buffer)) | false |
Lib.IntTypes.fst | Lib.IntTypes.secret | val secret: #t:inttype -> x:int_t t PUB -> y:int_t t SEC{v x == v y} | val secret: #t:inttype -> x:int_t t PUB -> y:int_t t SEC{v x == v y} | let secret #t x = x | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 18,
"start_col": 0,
"start_line": 18
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | x: Lib.IntTypes.int_t t Lib.IntTypes.PUB
-> y: Lib.IntTypes.int_t t Lib.IntTypes.SEC {Lib.IntTypes.v x == Lib.IntTypes.v y} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"Lib.IntTypes.SEC",
"Prims.eq2",
"Lib.IntTypes.range_t",
"Lib.IntTypes.v"
] | [] | false | false | false | false | false | let secret #t x =
| x | false |
Lib.IntTypes.fst | Lib.IntTypes.v_injective | val v_injective: #t:inttype -> #l:secrecy_level -> a:int_t t l -> Lemma
(mk_int (v #t #l a) == a)
[SMTPat (v #t #l a)] | val v_injective: #t:inttype -> #l:secrecy_level -> a:int_t t l -> Lemma
(mk_int (v #t #l a) == a)
[SMTPat (v #t #l a)] | let v_injective #t #l a =
v_extensionality a (mk_int (v a)) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 35,
"end_line": 58,
"start_col": 0,
"start_line": 57
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma (ensures Lib.IntTypes.mk_int (Lib.IntTypes.v a) == a)
[SMTPat (Lib.IntTypes.v a)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Lib.IntTypes.v_extensionality",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.v",
"Prims.unit"
] | [] | true | false | true | false | false | let v_injective #t #l a =
| v_extensionality a (mk_int (v a)) | false |
Spec.Exponentiation.fst | Spec.Exponentiation.exp_double_fw_lemma | val exp_double_fw_lemma: #t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits} -> l:pos ->
Lemma (k.to.refl (exp_double_fw k a1 bBits b1 a2 b2 l) ==
S.exp_double_fw k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 l) | val exp_double_fw_lemma: #t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits} -> l:pos ->
Lemma (k.to.refl (exp_double_fw k a1 bBits b1 a2 b2 l) ==
S.exp_double_fw k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 l) | let exp_double_fw_lemma #t k a1 bBits b1 a2 b2 l =
let acc0 =
if bBits % l = 0 then one ()
else begin
let bits_c1 = S.get_ith_lbits bBits b1 (bBits / l * l) l in
let bits_c2 = S.get_ith_lbits bBits b2 (bBits / l * l) l in
let acc_a1 = pow k a1 bits_c1 in
let acc_a2 = pow k a2 bits_c2 in
pow_lemma k a1 bits_c1;
pow_lemma k a2 bits_c2;
k.mul acc_a1 acc_a2 end in
exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 (bBits / l) | {
"file_name": "specs/Spec.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 68,
"end_line": 179,
"start_col": 0,
"start_line": 167
} | module Spec.Exponentiation
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
module S = Lib.Exponentiation
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 1"
val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in
let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in
k.to.refl acc == accs /\ k.to.refl c == cs)
let rec exp_rl_lemma_loop #t k a bBits b i =
let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a) in
let inp1 = (one, a) in
let f0 = S.exp_rl_f k.to.comm_monoid bBits b in
let f1 = exp_rl_f k bBits b in
if i = 0 then begin
Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1 end
else begin
exp_rl_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1) end
let exp_rl_lemma #t k a bBits b =
exp_rl_lemma_loop #t k a bBits b bBits
val exp_mont_ladder_swap_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (r0s, r1s, sws) =
Loops.repeati i (S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a, 0) in
let (r0, r1, sw) =
Loops.repeati i (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
k.to.refl r0 == r0s /\ k.to.refl r1 == r1s /\ sw == sws)
let rec exp_mont_ladder_swap_lemma_loop #t k a bBits b i =
let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a, 0) in
let inp1 = (one, a, 0) in
let f0 = S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b in
let f1 = exp_mont_ladder_swap_f k bBits b in
if i = 0 then begin
Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1 end
else begin
exp_mont_ladder_swap_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1) end
let exp_mont_ladder_swap_lemma #t k a bBits b =
exp_mont_ladder_swap_lemma_loop #t k a bBits b bBits
val exp_pow2_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> i:nat{i <= b} ->
Lemma (
let accs = Loops.repeat i (S.sqr k.to.comm_monoid) (k.to.refl a) in
let acc = Loops.repeat i k.sqr a in
k.to.refl acc == accs)
let rec exp_pow2_lemma_loop #t k a b i =
if i = 0 then begin
Loops.eq_repeat0 (S.sqr k.to.comm_monoid) (k.to.refl a);
Loops.eq_repeat0 k.sqr a end
else begin
exp_pow2_lemma_loop #t k a b (i - 1);
Loops.unfold_repeat b (S.sqr k.to.comm_monoid) (k.to.refl a) (i - 1);
Loops.unfold_repeat b k.sqr a (i - 1) end
let exp_pow2_lemma #t k a b =
exp_pow2_lemma_loop k a b b
#push-options "--fuel 1"
let pow_eq0 #t k a = ()
let pow_unfold #t k a i = ()
let rec pow_lemma #t k a b =
if b = 0 then ()
else pow_lemma k a (b - 1)
#pop-options
val exp_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma (
let acc = Loops.repeati i (exp_fw_f k a bBits b l) acc0 in
let accs = Loops.repeati i (S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l) (k.to.refl acc0) in
k.to.refl acc == accs)
let rec exp_fw_lemma_loop #t k a bBits b l acc0 i =
let f0 = exp_fw_f k a bBits b l in
let f1 = S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l in
if i = 0 then begin
Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0) end
else begin
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b l (i - 1) in
exp_fw_lemma_loop #t k a bBits b l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a bits_l1 end
let exp_fw_lemma #t k a bBits b l =
let acc0 =
if bBits % l = 0 then one ()
else begin
let bits_c = S.get_ith_lbits bBits b (bBits / l * l) l in
pow_lemma k a bits_c;
pow k a bits_c end in
exp_fw_lemma_loop #t k a bBits b l acc0 (bBits / l)
// Double exponentiation [a1^b1 `mul` a2^b2]
//-------------------------------------------
val exp_double_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma
(let acc = Loops.repeati i (exp_double_fw_f k a1 bBits b1 a2 b2 l) acc0 in
let accs = Loops.repeati i
(S.exp_double_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 l) (k.to.refl acc0) in
k.to.refl acc == accs)
let rec exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 i =
let f0 = exp_double_fw_f k a1 bBits b1 a2 b2 l in
let f1 = S.exp_double_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 l in
if i = 0 then begin
Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0) end
else begin
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b1 l (i - 1) in
let bits_l2 = S.get_bits_l bBits b2 l (i - 1) in
exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a1 bits_l1;
pow_lemma k a2 bits_l2 end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Spec.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Spec.Exponentiation.concrete_ops t ->
a1: t ->
bBits: Prims.nat ->
b1: Prims.nat{b1 < Prims.pow2 bBits} ->
a2: t ->
b2: Prims.nat{b2 < Prims.pow2 bBits} ->
l: Prims.pos
-> FStar.Pervasives.Lemma
(ensures
Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k)
(Spec.Exponentiation.exp_double_fw k a1 bBits b1 a2 b2 l) ==
Lib.Exponentiation.exp_double_fw (Mkto_comm_monoid?.comm_monoid (Mkconcrete_ops?.to k))
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a1)
bBits
b1
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a2)
b2
l) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Exponentiation.concrete_ops",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Spec.Exponentiation.exp_double_fw_lemma_loop",
"Prims.op_Division",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Spec.Exponentiation.one",
"Prims.bool",
"Spec.Exponentiation.__proj__Mkconcrete_ops__item__mul",
"Prims.unit",
"Spec.Exponentiation.pow_lemma",
"Spec.Exponentiation.pow",
"Lib.Exponentiation.get_ith_lbits",
"FStar.Mul.op_Star"
] | [] | false | false | true | false | false | let exp_double_fw_lemma #t k a1 bBits b1 a2 b2 l =
| let acc0 =
if bBits % l = 0
then one ()
else
let bits_c1 = S.get_ith_lbits bBits b1 ((bBits / l) * l) l in
let bits_c2 = S.get_ith_lbits bBits b2 ((bBits / l) * l) l in
let acc_a1 = pow k a1 bits_c1 in
let acc_a2 = pow k a2 bits_c2 in
pow_lemma k a1 bits_c1;
pow_lemma k a2 bits_c2;
k.mul acc_a1 acc_a2
in
exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 (bBits / l) | false |
Spec.Exponentiation.fst | Spec.Exponentiation.exp_four_fw_lemma_loop | val exp_four_fw_lemma_loop:
#t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits}
-> a3:t -> b3:nat{b3 < pow2 bBits}
-> a4:t -> b4:nat{b4 < pow2 bBits}
-> l:pos -> acc0:t -> i:nat{i <= bBits / l} ->
Lemma
(let acc = Loops.repeati i (exp_four_fw_f k a1 bBits b1 a2 b2 a3 b3 a4 b4 l) acc0 in
let accs = Loops.repeati i
(S.exp_four_fw_f
k.to.comm_monoid (k.to.refl a1) bBits b1
(k.to.refl a2) b2 (k.to.refl a3) b3 (k.to.refl a4) b4 l) (k.to.refl acc0) in
k.to.refl acc == accs) | val exp_four_fw_lemma_loop:
#t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits}
-> a3:t -> b3:nat{b3 < pow2 bBits}
-> a4:t -> b4:nat{b4 < pow2 bBits}
-> l:pos -> acc0:t -> i:nat{i <= bBits / l} ->
Lemma
(let acc = Loops.repeati i (exp_four_fw_f k a1 bBits b1 a2 b2 a3 b3 a4 b4 l) acc0 in
let accs = Loops.repeati i
(S.exp_four_fw_f
k.to.comm_monoid (k.to.refl a1) bBits b1
(k.to.refl a2) b2 (k.to.refl a3) b3 (k.to.refl a4) b4 l) (k.to.refl acc0) in
k.to.refl acc == accs) | let rec exp_four_fw_lemma_loop #t k a1 bBits b1 a2 b2 a3 b3 a4 b4 l acc0 i =
let f0 = exp_four_fw_f k a1 bBits b1 a2 b2 a3 b3 a4 b4 l in
let f1 = S.exp_four_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1
(k.to.refl a2) b2 (k.to.refl a3) b3 (k.to.refl a4) b4 l in
if i = 0 then begin
Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0) end
else begin
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b1 l (i - 1) in
let bits_l2 = S.get_bits_l bBits b2 l (i - 1) in
let bits_l3 = S.get_bits_l bBits b3 l (i - 1) in
let bits_l4 = S.get_bits_l bBits b4 l (i - 1) in
exp_four_fw_lemma_loop #t k a1 bBits b1 a2 b2 a3 b3 a4 b4 l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a1 bits_l1;
pow_lemma k a2 bits_l2;
pow_lemma k a3 bits_l3;
pow_lemma k a4 bits_l4 end | {
"file_name": "specs/Spec.Exponentiation.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 220,
"start_col": 0,
"start_line": 199
} | module Spec.Exponentiation
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
module S = Lib.Exponentiation
module Loops = Lib.LoopCombinators
#set-options "--z3rlimit 50 --fuel 0 --ifuel 1"
val exp_rl_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (accs, cs) = Loops.repeati i (S.exp_rl_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a) in
let (acc, c) = Loops.repeati i (exp_rl_f k bBits b) (one, a) in
k.to.refl acc == accs /\ k.to.refl c == cs)
let rec exp_rl_lemma_loop #t k a bBits b i =
let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a) in
let inp1 = (one, a) in
let f0 = S.exp_rl_f k.to.comm_monoid bBits b in
let f1 = exp_rl_f k bBits b in
if i = 0 then begin
Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1 end
else begin
exp_rl_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1) end
let exp_rl_lemma #t k a bBits b =
exp_rl_lemma_loop #t k a bBits b bBits
val exp_mont_ladder_swap_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> i:nat{i <= bBits} ->
Lemma (let one = k.one () in
let (r0s, r1s, sws) =
Loops.repeati i (S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b) (k.to.refl one, k.to.refl a, 0) in
let (r0, r1, sw) =
Loops.repeati i (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
k.to.refl r0 == r0s /\ k.to.refl r1 == r1s /\ sw == sws)
let rec exp_mont_ladder_swap_lemma_loop #t k a bBits b i =
let one = k.one () in
let inp0 = (k.to.refl one, k.to.refl a, 0) in
let inp1 = (one, a, 0) in
let f0 = S.exp_mont_ladder_swap_f k.to.comm_monoid bBits b in
let f1 = exp_mont_ladder_swap_f k bBits b in
if i = 0 then begin
Loops.eq_repeati0 bBits f0 inp0;
Loops.eq_repeati0 bBits f1 inp1 end
else begin
exp_mont_ladder_swap_lemma_loop #t k a bBits b (i - 1);
Loops.unfold_repeati bBits f0 inp0 (i - 1);
Loops.unfold_repeati bBits f1 inp1 (i - 1) end
let exp_mont_ladder_swap_lemma #t k a bBits b =
exp_mont_ladder_swap_lemma_loop #t k a bBits b bBits
val exp_pow2_lemma_loop: #t:Type -> k:concrete_ops t -> a:t -> b:nat -> i:nat{i <= b} ->
Lemma (
let accs = Loops.repeat i (S.sqr k.to.comm_monoid) (k.to.refl a) in
let acc = Loops.repeat i k.sqr a in
k.to.refl acc == accs)
let rec exp_pow2_lemma_loop #t k a b i =
if i = 0 then begin
Loops.eq_repeat0 (S.sqr k.to.comm_monoid) (k.to.refl a);
Loops.eq_repeat0 k.sqr a end
else begin
exp_pow2_lemma_loop #t k a b (i - 1);
Loops.unfold_repeat b (S.sqr k.to.comm_monoid) (k.to.refl a) (i - 1);
Loops.unfold_repeat b k.sqr a (i - 1) end
let exp_pow2_lemma #t k a b =
exp_pow2_lemma_loop k a b b
#push-options "--fuel 1"
let pow_eq0 #t k a = ()
let pow_unfold #t k a i = ()
let rec pow_lemma #t k a b =
if b = 0 then ()
else pow_lemma k a (b - 1)
#pop-options
val exp_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma (
let acc = Loops.repeati i (exp_fw_f k a bBits b l) acc0 in
let accs = Loops.repeati i (S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l) (k.to.refl acc0) in
k.to.refl acc == accs)
let rec exp_fw_lemma_loop #t k a bBits b l acc0 i =
let f0 = exp_fw_f k a bBits b l in
let f1 = S.exp_fw_f k.to.comm_monoid (k.to.refl a) bBits b l in
if i = 0 then begin
Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0) end
else begin
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b l (i - 1) in
exp_fw_lemma_loop #t k a bBits b l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a bits_l1 end
let exp_fw_lemma #t k a bBits b l =
let acc0 =
if bBits % l = 0 then one ()
else begin
let bits_c = S.get_ith_lbits bBits b (bBits / l * l) l in
pow_lemma k a bits_c;
pow k a bits_c end in
exp_fw_lemma_loop #t k a bBits b l acc0 (bBits / l)
// Double exponentiation [a1^b1 `mul` a2^b2]
//-------------------------------------------
val exp_double_fw_lemma_loop: #t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits} -> l:pos
-> acc0:t -> i:nat{i <= bBits / l} ->
Lemma
(let acc = Loops.repeati i (exp_double_fw_f k a1 bBits b1 a2 b2 l) acc0 in
let accs = Loops.repeati i
(S.exp_double_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 l) (k.to.refl acc0) in
k.to.refl acc == accs)
let rec exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 i =
let f0 = exp_double_fw_f k a1 bBits b1 a2 b2 l in
let f1 = S.exp_double_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 l in
if i = 0 then begin
Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0) end
else begin
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b1 l (i - 1) in
let bits_l2 = S.get_bits_l bBits b2 l (i - 1) in
exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a1 bits_l1;
pow_lemma k a2 bits_l2 end
let exp_double_fw_lemma #t k a1 bBits b1 a2 b2 l =
let acc0 =
if bBits % l = 0 then one ()
else begin
let bits_c1 = S.get_ith_lbits bBits b1 (bBits / l * l) l in
let bits_c2 = S.get_ith_lbits bBits b2 (bBits / l * l) l in
let acc_a1 = pow k a1 bits_c1 in
let acc_a2 = pow k a2 bits_c2 in
pow_lemma k a1 bits_c1;
pow_lemma k a2 bits_c2;
k.mul acc_a1 acc_a2 end in
exp_double_fw_lemma_loop #t k a1 bBits b1 a2 b2 l acc0 (bBits / l)
// [a1^b1 `mul` a2^b2 `mul` a3^b3 `mul` a4^b4]
//----------------------------------------------
val exp_four_fw_lemma_loop:
#t:Type -> k:concrete_ops t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits}
-> a3:t -> b3:nat{b3 < pow2 bBits}
-> a4:t -> b4:nat{b4 < pow2 bBits}
-> l:pos -> acc0:t -> i:nat{i <= bBits / l} ->
Lemma
(let acc = Loops.repeati i (exp_four_fw_f k a1 bBits b1 a2 b2 a3 b3 a4 b4 l) acc0 in
let accs = Loops.repeati i
(S.exp_four_fw_f
k.to.comm_monoid (k.to.refl a1) bBits b1
(k.to.refl a2) b2 (k.to.refl a3) b3 (k.to.refl a4) b4 l) (k.to.refl acc0) in
k.to.refl acc == accs) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "Spec.Exponentiation.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"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": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Spec.Exponentiation.concrete_ops t ->
a1: t ->
bBits: Prims.nat ->
b1: Prims.nat{b1 < Prims.pow2 bBits} ->
a2: t ->
b2: Prims.nat{b2 < Prims.pow2 bBits} ->
a3: t ->
b3: Prims.nat{b3 < Prims.pow2 bBits} ->
a4: t ->
b4: Prims.nat{b4 < Prims.pow2 bBits} ->
l: Prims.pos ->
acc0: t ->
i: Prims.nat{i <= bBits / l}
-> FStar.Pervasives.Lemma
(ensures
(let acc =
Lib.LoopCombinators.repeati i
(Spec.Exponentiation.exp_four_fw_f k a1 bBits b1 a2 b2 a3 b3 a4 b4 l)
acc0
in
let accs =
Lib.LoopCombinators.repeati i
(Lib.Exponentiation.exp_four_fw_f (Mkto_comm_monoid?.comm_monoid (Mkconcrete_ops?.to k))
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a1) bBits b1
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a2) b2
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a3) b3
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) a4) b4 l)
(Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) acc0)
in
Mkto_comm_monoid?.refl (Mkconcrete_ops?.to k) acc == accs)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Spec.Exponentiation.concrete_ops",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Prims.op_LessThanOrEqual",
"Prims.op_Division",
"Prims.op_Equality",
"Prims.int",
"Lib.LoopCombinators.eq_repeati0",
"Spec.Exponentiation.__proj__Mkto_comm_monoid__item__a_spec",
"Spec.Exponentiation.__proj__Mkconcrete_ops__item__to",
"Spec.Exponentiation.__proj__Mkto_comm_monoid__item__refl",
"Prims.unit",
"Prims.bool",
"Spec.Exponentiation.pow_lemma",
"Spec.Exponentiation.exp_pow2_lemma",
"Lib.LoopCombinators.unfold_repeati",
"Prims.op_Subtraction",
"Spec.Exponentiation.exp_four_fw_lemma_loop",
"Lib.Exponentiation.get_bits_l",
"Lib.LoopCombinators.repeati",
"Lib.Exponentiation.exp_four_fw_f",
"Spec.Exponentiation.__proj__Mkto_comm_monoid__item__comm_monoid",
"Spec.Exponentiation.exp_four_fw_f"
] | [
"recursion"
] | false | false | true | false | false | let rec exp_four_fw_lemma_loop #t k a1 bBits b1 a2 b2 a3 b3 a4 b4 l acc0 i =
| let f0 = exp_four_fw_f k a1 bBits b1 a2 b2 a3 b3 a4 b4 l in
let f1 =
S.exp_four_fw_f k.to.comm_monoid (k.to.refl a1) bBits b1 (k.to.refl a2) b2 (k.to.refl a3) b3
(k.to.refl a4) b4 l
in
if i = 0
then
(Loops.eq_repeati0 i f0 acc0;
Loops.eq_repeati0 i f1 (k.to.refl acc0))
else
let acc1 = Loops.repeati (i - 1) f0 acc0 in
let bits_l1 = S.get_bits_l bBits b1 l (i - 1) in
let bits_l2 = S.get_bits_l bBits b2 l (i - 1) in
let bits_l3 = S.get_bits_l bBits b3 l (i - 1) in
let bits_l4 = S.get_bits_l bBits b4 l (i - 1) in
exp_four_fw_lemma_loop #t k a1 bBits b1 a2 b2 a3 b3 a4 b4 l acc0 (i - 1);
Loops.unfold_repeati i f0 acc0 (i - 1);
Loops.unfold_repeati i f1 (k.to.refl acc0) (i - 1);
exp_pow2_lemma k acc1 l;
pow_lemma k a1 bits_l1;
pow_lemma k a2 bits_l2;
pow_lemma k a3 bits_l3;
pow_lemma k a4 bits_l4 | false |
Lib.IntTypes.fst | Lib.IntTypes.mk_int | val mk_int: #t:inttype -> #l:secrecy_level -> n:range_t t -> u:int_t t l{v u == n} | val mk_int: #t:inttype -> #l:secrecy_level -> n:range_t t -> u:int_t t l{v u == n} | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 33,
"start_col": 0,
"start_line": 21
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | n: Lib.IntTypes.range_t t -> u147: Lib.IntTypes.int_t t l {Lib.IntTypes.v u147 == n} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.range_t",
"FStar.UInt8.uint_to_t",
"FStar.UInt16.uint_to_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt64.uint_to_t",
"FStar.UInt128.uint_to_t",
"FStar.Int8.int_to_t",
"FStar.Int16.int_to_t",
"FStar.Int32.int_to_t",
"FStar.Int64.int_to_t",
"FStar.Int128.int_to_t",
"Lib.IntTypes.int_t",
"Prims.eq2",
"Lib.IntTypes.v"
] | [] | false | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.mul64_wide | val mul64_wide: uint64 -> uint64 -> uint128 | val mul64_wide: uint64 -> uint64 -> uint128 | let mul64_wide a b = UInt128.mul_wide a b | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 41,
"end_line": 358,
"start_col": 0,
"start_line": 358
} | 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 = () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.uint64 -> b: Lib.IntTypes.uint64 -> Lib.IntTypes.uint128 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.UInt128.mul_wide",
"Lib.IntTypes.uint128"
] | [] | false | false | false | true | false | let mul64_wide a b =
| UInt128.mul_wide a b | false |
Lib.IntTypes.fst | Lib.IntTypes.mul_s64_wide | val mul_s64_wide: int64 -> int64 -> int128 | val mul_s64_wide: int64 -> int64 -> int128 | let mul_s64_wide a b = Int128.mul_wide a b | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 362,
"start_col": 0,
"start_line": 362
} | 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 = () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int64 -> b: Lib.IntTypes.int64 -> Lib.IntTypes.int128 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.int64",
"FStar.Int128.mul_wide",
"Lib.IntTypes.int128"
] | [] | false | false | false | true | false | let mul_s64_wide a b =
| Int128.mul_wide a b | false |
Lib.IntTypes.fst | Lib.IntTypes.size_to_uint32 | val size_to_uint32: s:size_t -> u:uint32{u == u32 (v s)} | val size_to_uint32: s:size_t -> u:uint32{u == u32 (v s)} | let size_to_uint32 x = x | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 70,
"start_col": 0,
"start_line": 70
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | s: Lib.IntTypes.size_t -> u232: Lib.IntTypes.uint32{u232 == Lib.IntTypes.u32 (Lib.IntTypes.v s)} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"Lib.IntTypes.uint32",
"Prims.eq2",
"Lib.IntTypes.u32",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB"
] | [] | false | false | false | false | false | let size_to_uint32 x =
| x | false |
Lib.IntTypes.fst | Lib.IntTypes.u128 | val u128: n:range_t U64 -> u:uint128{v #U128 u == n} | val u128: n:range_t U64 -> u:uint128{v #U128 u == n} | let u128 n = FStar.UInt128.uint64_to_uint128 (u64 n) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 52,
"end_line": 62,
"start_col": 0,
"start_line": 62
} | 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 = () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | n: Lib.IntTypes.range_t Lib.IntTypes.U64 -> u218: Lib.IntTypes.uint128{Lib.IntTypes.v u218 == n} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.range_t",
"Lib.IntTypes.U64",
"FStar.UInt128.uint64_to_uint128",
"Lib.IntTypes.u64",
"Lib.IntTypes.uint128",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Lib.IntTypes.U128",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC"
] | [] | false | false | false | false | false | let u128 n =
| FStar.UInt128.uint64_to_uint128 (u64 n) | false |
Lib.IntTypes.fst | Lib.IntTypes.int64_to_uint128 | val int64_to_uint128: a:Int64.t -> b:UInt128.t{UInt128.v b == Int64.v a % pow2 128} | 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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 108,
"start_col": 0,
"start_line": 108
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: FStar.Int64.t -> b: FStar.UInt128.t{FStar.UInt128.v b == FStar.Int64.v a % Prims.pow2 128} | Prims.Tot | [
"total"
] | [] | [
"FStar.Int64.t",
"Lib.IntTypes.int128_to_uint128",
"Lib.IntTypes.int64_to_int128",
"FStar.UInt128.t",
"Prims.eq2",
"Prims.int",
"FStar.UInt128.v",
"Prims.op_Modulus",
"FStar.Int64.v",
"Prims.pow2"
] | [] | false | false | false | false | false | let int64_to_uint128 a =
| int128_to_uint128 (int64_to_int128 a) | false |
Lib.IntTypes.fst | Lib.IntTypes.byte_to_uint8 | val byte_to_uint8: s:byte_t -> u:uint8{u == u8 (v s)} | val byte_to_uint8: s:byte_t -> u:uint8{u == u8 (v s)} | let byte_to_uint8 x = x | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 74,
"start_col": 0,
"start_line": 74
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | s: Lib.IntTypes.byte_t -> u238: Lib.IntTypes.uint8{u238 == Lib.IntTypes.u8 (Lib.IntTypes.v s)} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.byte_t",
"Lib.IntTypes.uint8",
"Prims.eq2",
"Lib.IntTypes.u8",
"Lib.IntTypes.v",
"Lib.IntTypes.U8",
"Lib.IntTypes.PUB"
] | [] | false | false | false | false | false | let byte_to_uint8 x =
| x | false |
Lib.IntTypes.fst | Lib.IntTypes.i128 | val i128 (n:range_t S64) : u:int128{v #S128 u == n} | val i128 (n:range_t S64) : u:int128{v #S128 u == n} | let i128 n =
assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 68,
"start_col": 0,
"start_line": 66
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | n: Lib.IntTypes.range_t Lib.IntTypes.S64 -> u221: Lib.IntTypes.int128{Lib.IntTypes.v u221 == n} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.range_t",
"Lib.IntTypes.S64",
"Lib.IntTypes.sint",
"Lib.IntTypes.S128",
"Lib.IntTypes.SEC",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.pow2",
"Prims.op_Subtraction",
"Lib.IntTypes.bits",
"Lib.IntTypes.int128",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"Lib.IntTypes.v"
] | [] | false | false | false | false | false | let i128 n =
| assert_norm (pow2 (bits S64 - 1) <= pow2 (bits S128 - 1));
sint #S128 #SEC n | false |
Lib.IntTypes.fst | Lib.IntTypes.v_extensionality | 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) | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 55,
"start_col": 0,
"start_line": 43
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma (requires Lib.IntTypes.v a == Lib.IntTypes.v b) (ensures a == b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.UInt8.v_inj",
"FStar.UInt16.v_inj",
"FStar.UInt32.v_inj",
"FStar.UInt64.v_inj",
"FStar.UInt128.v_inj",
"FStar.Int8.v_inj",
"FStar.Int16.v_inj",
"FStar.Int32.v_inj",
"FStar.Int64.v_inj",
"FStar.Int128.v_inj",
"Prims.unit"
] | [] | false | false | true | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.size_to_uint64 | val size_to_uint64: s:size_t -> u:uint64{u == u64 (v s)} | val size_to_uint64: s:size_t -> u:uint64{u == u64 (v s)} | let size_to_uint64 x = Int.Cast.uint32_to_uint64 x | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 72,
"start_col": 0,
"start_line": 72
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | s: Lib.IntTypes.size_t -> u235: Lib.IntTypes.uint64{u235 == Lib.IntTypes.u64 (Lib.IntTypes.v s)} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size_t",
"FStar.Int.Cast.uint32_to_uint64",
"Lib.IntTypes.uint64",
"Prims.eq2",
"Lib.IntTypes.u64",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB"
] | [] | false | false | false | false | false | let size_to_uint64 x =
| Int.Cast.uint32_to_uint64 x | false |
Lib.IntTypes.fst | Lib.IntTypes.uint64_to_int128 | val uint64_to_int128: a:UInt64.t -> b:Int128.t{Int128.v b == UInt64.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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 105,
"start_col": 0,
"start_line": 105
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: FStar.UInt64.t -> b: FStar.Int128.t{FStar.Int128.v b == FStar.UInt64.v a} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt64.t",
"Lib.IntTypes.uint128_to_int128",
"FStar.Int.Cast.Full.uint64_to_uint128",
"FStar.Int128.t",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.Int.size",
"FStar.Int128.n",
"FStar.UInt.size",
"FStar.UInt64.n",
"FStar.Int128.v",
"FStar.UInt64.v"
] | [] | false | false | false | false | false | let uint64_to_int128 a =
| uint128_to_int128 (Int.Cast.Full.uint64_to_uint128 a) | false |
Lib.IntTypes.fst | Lib.IntTypes.add_mod | val add_mod: #t:inttype{unsigned t} -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l | val add_mod: #t:inttype{unsigned t} -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 290,
"start_col": 0,
"start_line": 283
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l -> Lib.IntTypes.int_t t l | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.UInt8.rem",
"FStar.UInt8.add_mod",
"FStar.UInt8.__uint_to_t",
"FStar.UInt16.add_mod",
"FStar.UInt32.add_mod",
"FStar.UInt64.add_mod",
"FStar.UInt128.add_mod"
] | [] | false | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.zeros | val zeros: t:inttype -> l:secrecy_level -> n:int_t t l{v n = 0} | val zeros: t:inttype -> l:secrecy_level -> n:int_t t l{v n = 0} | let zeros t l = mk_int 0 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 280,
"start_col": 0,
"start_line": 280
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | t: Lib.IntTypes.inttype -> l: Lib.IntTypes.secrecy_level
-> n: Lib.IntTypes.int_t t l {Lib.IntTypes.v n = 0} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.int_t",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.v"
] | [] | false | false | false | false | false | let zeros t l =
| mk_int 0 | false |
Lib.IntTypes.fst | Lib.IntTypes.int128_to_uint64 | val int128_to_uint64: a:Int128.t -> b:UInt64.t{UInt64.v b == Int128.v a % pow2 64} | 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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 78,
"end_line": 111,
"start_col": 0,
"start_line": 111
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: FStar.Int128.t -> b: FStar.UInt64.t{FStar.UInt64.v b == FStar.Int128.v a % Prims.pow2 64} | Prims.Tot | [
"total"
] | [] | [
"FStar.Int128.t",
"FStar.Int.Cast.Full.uint128_to_uint64",
"Lib.IntTypes.int128_to_uint128",
"FStar.UInt64.t",
"Prims.eq2",
"Prims.int",
"FStar.UInt64.v",
"Prims.op_Modulus",
"FStar.Int128.v",
"Prims.pow2"
] | [] | false | false | false | false | false | let int128_to_uint64 a =
| Int.Cast.Full.uint128_to_uint64 (int128_to_uint128 a) | false |
Lib.IntTypes.fst | Lib.IntTypes.ones | val ones: t:inttype -> l:secrecy_level -> n:int_t t l{v n = ones_v t} | val ones: t:inttype -> l:secrecy_level -> n:int_t t l{v n = ones_v t} | 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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 20,
"end_line": 278,
"start_col": 0,
"start_line": 266
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | t: Lib.IntTypes.inttype -> l: Lib.IntTypes.secrecy_level
-> n: Lib.IntTypes.int_t t l {Lib.IntTypes.v n = Lib.IntTypes.ones_v t} | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"FStar.UInt8.__uint_to_t",
"FStar.UInt16.__uint_to_t",
"FStar.UInt32.__uint_to_t",
"FStar.UInt64.__uint_to_t",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"Prims.int",
"FStar.UInt128.v",
"Prims.op_Subtraction",
"Prims.pow2",
"FStar.UInt128.t",
"FStar.UInt128.add",
"FStar.UInt128.shift_left",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt128.n",
"FStar.UInt64.v",
"FStar.UInt64.uint_to_t",
"FStar.UInt64.t",
"FStar.UInt128.uint64_to_uint128",
"Lib.IntTypes.mk_int",
"Prims.op_Minus",
"Lib.IntTypes.int_t",
"Prims.b2t",
"Prims.op_Equality",
"Lib.IntTypes.v",
"Lib.IntTypes.ones_v"
] | [] | false | false | false | false | false | 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) | false |
Lib.IntTypes.fst | Lib.IntTypes.sub_mod | val sub_mod: #t:inttype{unsigned t} -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l | val sub_mod: #t:inttype{unsigned t} -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 374,
"start_col": 0,
"start_line": 367
} | 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 = () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l -> Lib.IntTypes.int_t t l | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.UInt8.rem",
"FStar.UInt8.sub_mod",
"FStar.UInt8.__uint_to_t",
"FStar.UInt16.sub_mod",
"FStar.UInt32.sub_mod",
"FStar.UInt64.sub_mod",
"FStar.UInt128.sub_mod"
] | [] | false | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.incr | val incr: #t:inttype -> #l:secrecy_level
-> a:int_t t l{v a < maxint t}
-> int_t t l | val incr: #t:inttype -> #l:secrecy_level
-> a:int_t t l{v a < maxint t}
-> int_t t l | 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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 326,
"start_col": 0,
"start_line": 314
} | 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" | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l {Lib.IntTypes.v a < Lib.IntTypes.maxint t} -> Lib.IntTypes.int_t t l | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.maxint",
"FStar.UInt8.add",
"FStar.UInt8.__uint_to_t",
"FStar.UInt16.add",
"FStar.UInt16.__uint_to_t",
"FStar.UInt32.add",
"FStar.UInt32.__uint_to_t",
"FStar.UInt64.add",
"FStar.UInt64.__uint_to_t",
"FStar.UInt128.add",
"FStar.UInt128.uint_to_t",
"FStar.Int8.add",
"FStar.Int8.__int_to_t",
"FStar.Int16.add",
"FStar.Int16.__int_to_t",
"FStar.Int32.add",
"FStar.Int32.__int_to_t",
"FStar.Int64.add",
"FStar.Int64.__int_to_t",
"FStar.Int128.add",
"FStar.Int128.int_to_t"
] | [] | false | false | false | false | false | 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) | false |
Lib.IntTypes.fst | Lib.IntTypes.mul | val mul: #t:inttype{~(U128? t) /\ ~(S128? t)} -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l{range (v a * v b) t}
-> int_t t l | val mul: #t:inttype{~(U128? t) /\ ~(S128? t)} -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l{range (v a * v b) t}
-> int_t t l | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 354,
"start_col": 0,
"start_line": 344
} | 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 = () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
a: Lib.IntTypes.int_t t l ->
b: Lib.IntTypes.int_t t l {Lib.IntTypes.range (Lib.IntTypes.v a * Lib.IntTypes.v b) t}
-> Lib.IntTypes.int_t t l | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.l_and",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_U128",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Lib.IntTypes.range",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"FStar.UInt8.mul",
"FStar.UInt16.mul",
"FStar.UInt32.mul",
"FStar.UInt64.mul",
"FStar.Int8.mul",
"FStar.Int16.mul",
"FStar.Int32.mul",
"FStar.Int64.mul"
] | [] | false | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.mul_mod | val mul_mod: #t:inttype{unsigned t /\ ~(U128? t)} -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l | val mul_mod: #t:inttype{unsigned t /\ ~(U128? t)} -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 339,
"start_col": 0,
"start_line": 333
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l -> Lib.IntTypes.int_t t l | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.l_and",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Prims.l_not",
"Lib.IntTypes.uu___is_U128",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.UInt8.mul_mod",
"FStar.UInt16.mul_mod",
"FStar.UInt32.mul_mod",
"FStar.UInt64.mul_mod"
] | [] | false | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.add | val add: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l{range (v a + v b) t}
-> int_t t l | val add: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l{range (v a + v b) t}
-> int_t t l | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 307,
"start_col": 0,
"start_line": 295
} | 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 = () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
a: Lib.IntTypes.int_t t l ->
b: Lib.IntTypes.int_t t l {Lib.IntTypes.range (Lib.IntTypes.v a + Lib.IntTypes.v b) t}
-> Lib.IntTypes.int_t t l | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Lib.IntTypes.range",
"Prims.op_Addition",
"Lib.IntTypes.v",
"FStar.UInt8.add",
"FStar.UInt16.add",
"FStar.UInt32.add",
"FStar.UInt64.add",
"FStar.UInt128.add",
"FStar.Int8.add",
"FStar.Int16.add",
"FStar.Int32.add",
"FStar.Int64.add",
"FStar.Int128.add"
] | [] | false | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.decr | val decr: #t:inttype -> #l:secrecy_level
-> a:int_t t l{minint t < v a}
-> int_t t l | val decr: #t:inttype -> #l:secrecy_level
-> a:int_t t l{minint t < v a}
-> int_t t l | 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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 410,
"start_col": 0,
"start_line": 398
} | 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" | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l {Lib.IntTypes.minint t < Lib.IntTypes.v a} -> Lib.IntTypes.int_t t l | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.minint",
"Lib.IntTypes.v",
"FStar.UInt8.sub",
"FStar.UInt8.__uint_to_t",
"FStar.UInt16.sub",
"FStar.UInt16.__uint_to_t",
"FStar.UInt32.sub",
"FStar.UInt32.__uint_to_t",
"FStar.UInt64.sub",
"FStar.UInt64.__uint_to_t",
"FStar.UInt128.sub",
"FStar.UInt128.uint_to_t",
"FStar.Int8.sub",
"FStar.Int8.__int_to_t",
"FStar.Int16.sub",
"FStar.Int16.__int_to_t",
"FStar.Int32.sub",
"FStar.Int32.__int_to_t",
"FStar.Int64.sub",
"FStar.Int64.__int_to_t",
"FStar.Int128.sub",
"FStar.Int128.int_to_t"
] | [] | false | false | false | false | false | 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) | false |
Lib.IntTypes.fst | Lib.IntTypes.sub | val sub: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l{range (v a - v b) t}
-> int_t t l | val sub: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l{range (v a - v b) t}
-> int_t t l | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 391,
"start_col": 0,
"start_line": 379
} | 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 = () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
a: Lib.IntTypes.int_t t l ->
b: Lib.IntTypes.int_t t l {Lib.IntTypes.range (Lib.IntTypes.v a - Lib.IntTypes.v b) t}
-> Lib.IntTypes.int_t t l | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Lib.IntTypes.range",
"Prims.op_Subtraction",
"Lib.IntTypes.v",
"FStar.UInt8.sub",
"FStar.UInt16.sub",
"FStar.UInt32.sub",
"FStar.UInt64.sub",
"FStar.UInt128.sub",
"FStar.Int8.sub",
"FStar.Int16.sub",
"FStar.Int32.sub",
"FStar.Int64.sub",
"FStar.Int128.sub"
] | [] | false | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.logand | val logand: #t:inttype -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l | val logand: #t:inttype -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 509,
"start_col": 0,
"start_line": 492
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l -> Lib.IntTypes.int_t t l | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.UInt8.logand",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.UInt8.t",
"FStar.UInt8.__uint_to_t",
"FStar.UInt16.logand",
"FStar.UInt32.logand",
"FStar.UInt64.logand",
"FStar.UInt128.logand",
"FStar.Int8.logand",
"FStar.Int16.logand",
"FStar.Int32.logand",
"FStar.Int64.logand",
"FStar.Int128.logand"
] | [] | false | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.logand_ones | val logand_ones: #t:inttype -> #l:secrecy_level -> a:int_t t l ->
Lemma (v (a `logand` ones t l) == 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 =
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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 521,
"start_col": 0,
"start_line": 517
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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) | false |
Lib.IntTypes.fst | Lib.IntTypes.logand_zeros | val logand_zeros: #t:inttype -> #l:secrecy_level -> a:int_t t l ->
Lemma (v (a `logand` zeros t l) == 0) | val logand_zeros: #t:inttype -> #l:secrecy_level -> a:int_t t l ->
Lemma (v (a `logand` zeros t l) == 0) | 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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 515,
"start_col": 0,
"start_line": 511
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma
(ensures Lib.IntTypes.v (Lib.IntTypes.logand a (Lib.IntTypes.zeros t l)) == 0) | FStar.Pervasives.Lemma | [
"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.zeros",
"FStar.UInt.logand_lemma_1",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"FStar.Int.logand_lemma_1",
"Prims.unit"
] | [] | false | false | true | false | false | 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 |
Lib.IntTypes.fst | Lib.IntTypes.logxor_lemma1 | val logxor_lemma1: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(requires range (v a) U1 /\ range (v b) U1)
(ensures range (v (a `logxor` b)) U1) | val logxor_lemma1: #t:inttype -> #l:secrecy_level -> a:int_t t l -> b:int_t t l -> Lemma
(requires range (v a) U1 /\ range (v b) U1)
(ensures range (v (a `logxor` b)) U1) | 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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 478,
"start_col": 0,
"start_line": 469
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma
(requires
Lib.IntTypes.range (Lib.IntTypes.v a) Lib.IntTypes.U1 /\
Lib.IntTypes.range (Lib.IntTypes.v b) Lib.IntTypes.U1)
(ensures Lib.IntTypes.range (Lib.IntTypes.v (Lib.IntTypes.logxor a b)) Lib.IntTypes.U1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.Pervasives.Native.Mktuple2",
"Prims.int",
"Lib.IntTypes.v",
"FStar.UInt.logxor_lemma_1",
"Lib.IntTypes.bits",
"Prims.unit",
"FStar.UInt.logxor_commutative",
"FStar.UInt.logxor_self",
"Lib.IntTypes.v_extensionality"
] | [] | false | false | true | false | false | 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 |
Lib.IntTypes.fst | Lib.IntTypes.logand_spec | val logand_spec: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma (v (a `logand` b) == v a `logand_v` v b) | val logand_spec: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma (v (a `logand` b) == v a `logand_v` 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)
| _ -> () | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 540,
"start_col": 0,
"start_line": 533
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma
(ensures
Lib.IntTypes.v (Lib.IntTypes.logand a b) ==
Lib.IntTypes.logand_v (Lib.IntTypes.v a) (Lib.IntTypes.v b)) | FStar.Pervasives.Lemma | [
"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.logand_v",
"Lib.IntTypes.U1",
"Prims.unit",
"Lib.IntTypes.SEC",
"Lib.IntTypes.logand",
"Lib.IntTypes.u1"
] | [] | false | false | true | false | false | 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 (logand_v #U1 0 0 == 0 /\ logand_v #U1 0 1 == 0);
assert_norm (logand_v #U1 1 0 == 0 /\ logand_v #U1 1 1 == 1)
| _ -> () | false |
Lib.IntTypes.fst | Lib.IntTypes.logxor | val logxor: #t:inttype -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l | 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 =
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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 434,
"start_col": 0,
"start_line": 417
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l -> Lib.IntTypes.int_t t l | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.logand_le | 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) | 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 =
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)) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 80,
"end_line": 553,
"start_col": 0,
"start_line": 542
} | 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)
| _ -> () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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)) | false |
Lib.IntTypes.fst | Lib.IntTypes.logor_ones | val logor_ones: #t: inttype -> #l: secrecy_level -> a: int_t t l ->
Lemma (v (a `logor` ones t l) == ones_v t) | val logor_ones: #t: inttype -> #l: secrecy_level -> a: int_t t l ->
Lemma (v (a `logor` ones t l) == ones_v t) | 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)) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 116,
"end_line": 616,
"start_col": 0,
"start_line": 612
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma
(ensures Lib.IntTypes.v (Lib.IntTypes.logor a (Lib.IntTypes.ones t l)) == Lib.IntTypes.ones_v t) | FStar.Pervasives.Lemma | [
"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.ones",
"FStar.UInt.logor_lemma_2",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"FStar.Int.nth_lemma",
"FStar.Int.logor",
"FStar.Int.ones",
"Prims.unit"
] | [] | false | false | true | false | false | 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 |
Lib.IntTypes.fst | Lib.IntTypes.neq_mask | val neq_mask: #t:inttype{~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> int_t t SEC | val neq_mask: #t:inttype{~(S128? t)} -> a:int_t t SEC -> b:int_t t SEC -> int_t t SEC | let neq_mask #t a b = lognot (eq_mask #t a b) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 877,
"start_col": 0,
"start_line": 877
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.lognot",
"Lib.IntTypes.eq_mask"
] | [] | false | false | false | false | false | let neq_mask #t a b =
| lognot (eq_mask #t a b) | false |
Lib.IntTypes.fst | Lib.IntTypes.logor_disjoint | val logor_disjoint: #t:inttype{unsigned t} -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> m:nat{m < bits t}
-> Lemma
(requires 0 <= v a /\ v a < pow2 m /\ v b % pow2 m == 0)
(ensures v (a `logor` b) == v a + v b) | val logor_disjoint: #t:inttype{unsigned t} -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> m:nat{m < bits t}
-> Lemma
(requires 0 <= v a /\ v a < pow2 m /\ v b % pow2 m == 0)
(ensures v (a `logor` b) == v a + v b) | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 601,
"start_col": 0,
"start_line": 591
} | 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" | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l -> m: Prims.nat{m < Lib.IntTypes.bits t}
-> FStar.Pervasives.Lemma
(requires
0 <= Lib.IntTypes.v a /\ Lib.IntTypes.v a < Prims.pow2 m /\
Lib.IntTypes.v b % Prims.pow2 m == 0)
(ensures Lib.IntTypes.v (Lib.IntTypes.logor a b) == Lib.IntTypes.v a + Lib.IntTypes.v b) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Prims.nat",
"Prims.op_LessThan",
"Lib.IntTypes.bits",
"Prims.op_GreaterThan",
"FStar.UInt.logor_commutative",
"Lib.IntTypes.v",
"Prims.unit",
"FStar.UInt.logor_disjoint",
"Prims.bool",
"FStar.UInt.logor_lemma_1"
] | [] | false | false | true | false | false | let logor_disjoint #t #l a b m =
| if m > 0
then
(UInt.logor_disjoint #(bits t) (v b) (v a) m;
UInt.logor_commutative #(bits t) (v b) (v a))
else
(UInt.logor_commutative #(bits t) (v a) (v b);
UInt.logor_lemma_1 #(bits t) (v b)) | false |
Lib.IntTypes.fst | Lib.IntTypes.logor_zeros | val logor_zeros: #t: inttype -> #l: secrecy_level -> a: int_t t l ->
Lemma (v (a `logor` zeros t l) == 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 =
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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 112,
"end_line": 609,
"start_col": 0,
"start_line": 605
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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) | false |
Lib.IntTypes.fst | Lib.IntTypes.logor | val logor: #t:inttype -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l | val logor: #t:inttype -> #l:secrecy_level
-> int_t t l
-> int_t t l
-> int_t t l | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 587,
"start_col": 0,
"start_line": 570
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l -> Lib.IntTypes.int_t t l | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.UInt8.logor",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.UInt8.t",
"FStar.UInt8.__uint_to_t",
"FStar.UInt16.logor",
"FStar.UInt32.logor",
"FStar.UInt64.logor",
"FStar.UInt128.logor",
"FStar.Int8.logor",
"FStar.Int16.logor",
"FStar.Int32.logor",
"FStar.Int64.logor",
"FStar.Int128.logor"
] | [] | false | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.lognot_spec | val lognot_spec: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> Lemma (v (lognot a) == lognot_v (v a)) | val lognot_spec: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> Lemma (v (lognot a) == lognot_v (v a)) | 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)
| _ -> () | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 668,
"start_col": 0,
"start_line": 663
} | 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)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma
(ensures Lib.IntTypes.v (Lib.IntTypes.lognot a) == Lib.IntTypes.lognot_v (Lib.IntTypes.v a)) | FStar.Pervasives.Lemma | [
"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.lognot_v",
"Lib.IntTypes.U1",
"Prims.unit",
"Lib.IntTypes.SEC",
"Lib.IntTypes.lognot",
"Lib.IntTypes.u1"
] | [] | false | false | true | false | false | 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)
| _ -> () | false |
Lib.IntTypes.fst | Lib.IntTypes.lt_mask | val lt_mask: #t:inttype{unsigned t} -> int_t t SEC -> int_t t SEC -> int_t t SEC | val lt_mask: #t:inttype{unsigned t} -> int_t t SEC -> int_t t SEC -> int_t t SEC | let lt_mask #t a b = lognot (gte_mask a b) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 918,
"start_col": 0,
"start_line": 918
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.lognot",
"Lib.IntTypes.gte_mask"
] | [] | false | false | false | false | false | let lt_mask #t a b =
| lognot (gte_mask a b) | false |
Lib.IntTypes.fst | Lib.IntTypes.lognot | val lognot: #t:inttype -> #l:secrecy_level -> int_t t l -> int_t t l | val lognot: #t:inttype -> #l:secrecy_level -> int_t t l -> int_t t l | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 651,
"start_col": 0,
"start_line": 639
} | 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)
| _ -> () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> Lib.IntTypes.int_t t l | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"FStar.UInt8.rem",
"FStar.UInt8.lognot",
"FStar.UInt8.__uint_to_t",
"FStar.UInt16.lognot",
"FStar.UInt32.lognot",
"FStar.UInt64.lognot",
"FStar.UInt128.lognot",
"FStar.Int8.lognot",
"FStar.Int16.lognot",
"FStar.Int32.lognot",
"FStar.Int64.lognot",
"FStar.Int128.lognot"
] | [] | false | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.logxor_spec | 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) | 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 =
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)
| _ -> () | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 487,
"start_col": 0,
"start_line": 480
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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 (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)
| _ -> () | false |
Lib.IntTypes.fst | Lib.IntTypes.logand_mask | val logand_mask: #t:inttype{unsigned t} -> #l:secrecy_level -> a:uint_t t l -> b:uint_t t l -> m:pos{m < bits t} ->
Lemma
(requires v b == pow2 m - 1)
(ensures v (logand #t #l a b) == v a % pow2 m) | val logand_mask: #t:inttype{unsigned t} -> #l:secrecy_level -> a:uint_t t l -> b:uint_t t l -> m:pos{m < bits t} ->
Lemma
(requires v b == pow2 m - 1)
(ensures v (logand #t #l a b) == v a % pow2 m) | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 566,
"start_col": 0,
"start_line": 555
} | 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)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.uint_t t l -> b: Lib.IntTypes.uint_t t l -> m: Prims.pos{m < Lib.IntTypes.bits t}
-> FStar.Pervasives.Lemma (requires Lib.IntTypes.v b == Prims.pow2 m - 1)
(ensures Lib.IntTypes.v (Lib.IntTypes.logand a b) == Lib.IntTypes.v a % Prims.pow2 m) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.uint_t",
"Prims.pos",
"Prims.op_LessThan",
"Lib.IntTypes.bits",
"FStar.Pervasives.assert_norm",
"Prims.eq2",
"FStar.UInt8.t",
"FStar.UInt8.logand",
"FStar.UInt8.__uint_to_t",
"Prims.unit",
"FStar.UInt.logand_mask",
"FStar.UInt.to_uint_t",
"Lib.IntTypes.v"
] | [] | false | false | true | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.shift_right | val shift_right: #t:inttype -> #l:secrecy_level
-> int_t t l
-> shiftval t
-> int_t t l | val shift_right: #t:inttype -> #l:secrecy_level
-> int_t t l
-> shiftval t
-> int_t t l | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 684,
"start_col": 0,
"start_line": 672
} | 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)
| _ -> () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.shiftval t -> Lib.IntTypes.int_t t l | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.secrecy_level",
"Lib.IntTypes.int_t",
"Lib.IntTypes.shiftval",
"FStar.UInt8.shift_right",
"FStar.UInt16.shift_right",
"FStar.UInt32.shift_right",
"FStar.UInt64.shift_right",
"FStar.UInt128.shift_right",
"FStar.Int8.shift_arithmetic_right",
"FStar.Int16.shift_arithmetic_right",
"FStar.Int32.shift_arithmetic_right",
"FStar.Int64.shift_arithmetic_right",
"FStar.Int128.shift_arithmetic_right"
] | [] | false | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.ct_abs | 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)} | 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 =
match t with
| S8 -> Int8.ct_abs a
| S16 -> Int16.ct_abs a
| S32 -> Int32.ct_abs a
| S64 -> Int64.ct_abs a | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 786,
"start_col": 0,
"start_line": 781
} | 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)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)} | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.gte_mask | val gte_mask: #t:inttype{unsigned t} -> int_t t SEC -> b:int_t t SEC -> int_t t SEC | val gte_mask: #t:inttype{unsigned t} -> int_t t SEC -> b:int_t t SEC -> int_t t SEC | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 894,
"start_col": 0,
"start_line": 887
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.logor",
"Lib.IntTypes.lognot",
"FStar.UInt8.gte_mask",
"FStar.UInt16.gte_mask",
"FStar.UInt32.gte_mask",
"FStar.UInt64.gte_mask",
"FStar.UInt128.gte_mask"
] | [] | false | false | false | false | false | 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 |
Lib.IntTypes.fst | Lib.IntTypes.rotate_left | val rotate_left: #t:inttype -> #l:secrecy_level
-> a:int_t t l{unsigned t}
-> rotval t
-> int_t t l | val rotate_left: #t:inttype -> #l:secrecy_level
-> a:int_t t l{unsigned t}
-> rotval t
-> int_t t l | let rotate_left #t #l a b =
logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b)) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 778,
"start_col": 0,
"start_line": 777
} | 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)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l {Lib.IntTypes.unsigned t} -> b: Lib.IntTypes.rotval t
-> Lib.IntTypes.int_t t l | Prims.Tot | [
"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_left",
"Lib.IntTypes.shift_right",
"Lib.IntTypes.sub",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.size",
"Lib.IntTypes.bits"
] | [] | false | false | false | false | false | let rotate_left #t #l a b =
| logor (shift_left a b) (shift_right a (sub #U32 (size (bits t)) b)) | false |
Lib.IntTypes.fst | Lib.IntTypes.logor_spec | val logor_spec: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma (v (a `logor` b) == v a `logor_v` v b) | val logor_spec: #t:inttype -> #l:secrecy_level
-> a:int_t t l
-> b:int_t t l
-> Lemma (v (a `logor` b) == v a `logor_v` v b) | 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)
| _ -> () | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 635,
"start_col": 0,
"start_line": 628
} | 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)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> b: Lib.IntTypes.int_t t l
-> FStar.Pervasives.Lemma
(ensures
Lib.IntTypes.v (Lib.IntTypes.logor a b) ==
Lib.IntTypes.logor_v (Lib.IntTypes.v a) (Lib.IntTypes.v b)) | FStar.Pervasives.Lemma | [
"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.logor_v",
"Lib.IntTypes.U1",
"Prims.unit",
"Lib.IntTypes.SEC",
"Lib.IntTypes.logor",
"Lib.IntTypes.u1",
"Lib.IntTypes.zeros",
"Lib.IntTypes.ones"
] | [] | false | false | true | false | false | 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 (logor_v #U1 0 0 == 0 /\ logor_v #U1 0 1 == 1);
assert_norm (logor_v #U1 1 0 == 1 /\ logor_v #U1 1 1 == 1)
| _ -> () | false |
Lib.IntTypes.fst | Lib.IntTypes.eq_mask | val eq_mask: #t:inttype{~(S128? t)} -> int_t t SEC -> int_t t SEC -> int_t t SEC | val eq_mask: #t:inttype{~(S128? t)} -> int_t t SEC -> int_t t SEC -> int_t t SEC | 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)) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 75,
"end_line": 802,
"start_col": 0,
"start_line": 791
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.lognot",
"Lib.IntTypes.logxor",
"FStar.UInt8.eq_mask",
"FStar.UInt16.eq_mask",
"FStar.UInt32.eq_mask",
"FStar.UInt64.eq_mask",
"FStar.UInt128.eq_mask",
"FStar.Int.Cast.uint8_to_int8",
"Lib.IntTypes.to_u8",
"FStar.Int.Cast.uint16_to_int16",
"Lib.IntTypes.to_u16",
"FStar.Int.Cast.uint32_to_int32",
"Lib.IntTypes.to_u32",
"FStar.Int.Cast.uint64_to_int64",
"Lib.IntTypes.to_u64"
] | [] | false | false | false | false | false | 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)) | false |
Lib.IntTypes.fst | Lib.IntTypes.eq_mask_lemma | val eq_mask_lemma: #t:inttype{~(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)
[SMTPat (eq_mask #t a b)] | val eq_mask_lemma: #t:inttype{~(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)
[SMTPat (eq_mask #t a b)] | let eq_mask_lemma #t a b =
if signed t then eq_mask_lemma_signed a b
else eq_mask_lemma_unsigned a b | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 866,
"start_col": 0,
"start_line": 864
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)) [SMTPat (Lib.IntTypes.eq_mask a b)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.l_not",
"Prims.b2t",
"Lib.IntTypes.uu___is_S128",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.signed",
"Lib.IntTypes.eq_mask_lemma_signed",
"Prims.bool",
"Lib.IntTypes.eq_mask_lemma_unsigned",
"Prims.unit"
] | [] | false | false | true | false | false | 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 |
Lib.IntTypes.fst | Lib.IntTypes.logand_lemma | val logand_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 = 0 then v (a `logand` b) == 0 else v (a `logand` b) == v b)) | val logand_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 = 0 then v (a `logand` b) == 0 else v (a `logand` b) == v b)) | 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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 79,
"end_line": 531,
"start_col": 0,
"start_line": 523
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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 = 0 with
| true -> Lib.IntTypes.v (Lib.IntTypes.logand a b) == 0
| _ -> Lib.IntTypes.v (Lib.IntTypes.logand a b) == Lib.IntTypes.v b)
<:
Type0)) | FStar.Pervasives.Lemma | [
"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",
"Prims.unit",
"Lib.IntTypes.zeros",
"FStar.UInt.logand_commutative",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"FStar.Int.logand_commutative",
"Lib.IntTypes.logand_ones",
"Lib.IntTypes.logand_zeros"
] | [] | false | false | true | false | false | 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) | false |
Lib.IntTypes.fst | Lib.IntTypes.shift_right_value_aux_2 | 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) | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 722,
"start_col": 0,
"start_line": 696
} | 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 -> | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: FStar.Int.int_t n
-> FStar.Pervasives.Lemma (ensures FStar.Int.shift_arithmetic_right a 1 = a / 2) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.int_t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.shift_right_value_aux_3",
"Prims.unit",
"FStar.Int.sign_bit_positive",
"Prims.bool",
"Prims._assert",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Division",
"FStar.Math.Lemmas.lemma_div_plus",
"Prims.pow2",
"Prims.op_Subtraction",
"FStar.Math.Lemmas.pow2_double_mult",
"Prims.op_Addition",
"FStar.Math.Lemmas.pow2_double_sum",
"FStar.UInt.slice_left_lemma",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"FStar.UInt.append_lemma",
"FStar.BitVector.ones_vec",
"FStar.Seq.Base.append",
"FStar.BitVector.bv_t",
"FStar.UInt.to_vec",
"FStar.UInt.uint_t",
"FStar.UInt.shift_right",
"FStar.Int.to_vec",
"FStar.Int.shift_arithmetic_right",
"FStar.Int.to_uint",
"FStar.Int.sign_bit_negative"
] | [] | false | false | true | false | false | let shift_right_value_aux_2 #n a =
| if a >= 0
then
(Int.sign_bit_positive a;
UInt.shift_right_value_aux_3 #n a 1)
else
(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)) | false |
Lib.IntTypes.fst | Lib.IntTypes.rotate_right | val rotate_right: #t:inttype -> #l:secrecy_level
-> a:int_t t l{unsigned t}
-> rotval t
-> int_t t l | 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 =
logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b)) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 775,
"start_col": 0,
"start_line": 774
} | 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 = () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l {Lib.IntTypes.unsigned t} -> b: Lib.IntTypes.rotval t
-> Lib.IntTypes.int_t t l | Prims.Tot | [
"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"
] | [] | false | false | false | false | false | let rotate_right #t #l a b =
| logor (shift_right a b) (shift_left a (sub #U32 (size (bits t)) b)) | false |
Lib.IntTypes.fst | Lib.IntTypes.shift_left | 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) | 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 =
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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 768,
"start_col": 0,
"start_line": 756
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: Lib.IntTypes.int_t t l -> s: Lib.IntTypes.shiftval t -> Prims.Pure (Lib.IntTypes.int_t t l) | Prims.Pure | [] | [] | [
"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"
] | [] | false | false | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.shift_right_value_aux_3 | 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) | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 743,
"start_col": 0,
"start_line": 727
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: FStar.Int.int_t n -> s: Prims.pos{s < n}
-> FStar.Pervasives.Lemma (ensures FStar.Int.shift_arithmetic_right a s = a / Prims.pow2 s)
(decreases s) | FStar.Pervasives.Lemma | [
"lemma",
""
] | [] | [
"Prims.pos",
"FStar.Int.int_t",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.op_Equality",
"Prims.int",
"Lib.IntTypes.shift_right_value_aux_2",
"Prims.bool",
"FStar.Math.Lemmas.division_multiplication_lemma",
"Prims.pow2",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Math.Lemmas.pow2_double_mult",
"Prims._assert",
"FStar.Int.shift_arithmetic_right",
"Prims.op_Division",
"Lib.IntTypes.shift_right_value_aux_3",
"FStar.Seq.Base.equal",
"FStar.BitVector.shift_arithmetic_right_vec",
"FStar.BitVector.bv_t",
"FStar.Int.to_vec"
] | [
"recursion"
] | false | false | true | false | false | let rec shift_right_value_aux_3 #n a s =
| if s = 1
then shift_right_value_aux_2 #n a
else
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 | false |
Lib.IntTypes.fst | Lib.IntTypes.eq_mask_logand_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)] | 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 =
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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 84,
"end_line": 874,
"start_col": 0,
"start_line": 868
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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))] | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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) | false |
Lib.IntTypes.fst | Lib.IntTypes.logor_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)) | 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 =
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)) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 126,
"end_line": 626,
"start_col": 0,
"start_line": 618
} | 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)) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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)) | false |
Lib.IntTypes.fst | Lib.IntTypes.shift_right_value_aux_1 | 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) | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 69,
"end_line": 690,
"start_col": 0,
"start_line": 688
} | 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} -> | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: FStar.Int.int_t n -> s: Prims.nat{n <= s}
-> FStar.Pervasives.Lemma (ensures FStar.Int.shift_arithmetic_right a s = a / Prims.pow2 s) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Int.int_t",
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Prims.op_GreaterThanOrEqual",
"FStar.Int.sign_bit_positive",
"Prims.bool",
"FStar.Int.sign_bit_negative",
"Prims.unit",
"FStar.Math.Lemmas.pow2_le_compat"
] | [] | false | false | true | false | false | 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 | false |
Lib.IntTypes.fst | Lib.IntTypes.eq_mask_lemma_unsigned | 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) | 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 -> () | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 814,
"start_col": 0,
"start_line": 807
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)) | FStar.Pervasives.Lemma | [
"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.logxor",
"Lib.IntTypes.u1",
"Lib.IntTypes.lognot",
"Prims.unit"
] | [] | false | false | true | false | false | 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 -> () | false |
Lib.IntTypes.fst | Lib.IntTypes.ne | val ne: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | val ne: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | let ne #t x y = not (eq x y) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 1072,
"start_col": 0,
"start_line": 1072
} | 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 = () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | x: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> y: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"Prims.op_Negation",
"Lib.IntTypes.eq",
"Prims.bool"
] | [] | false | false | false | false | false | let ne #t x y =
| not (eq x y) | false |
Lib.IntTypes.fst | Lib.IntTypes.gt_mask | val gt_mask: #t:inttype{unsigned t} -> int_t t SEC -> b:int_t t SEC -> int_t t SEC | 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 = logand (gte_mask a b) (neq_mask a b) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 925,
"start_col": 0,
"start_line": 925
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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 | Prims.Tot | [
"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"
] | [] | false | false | false | false | false | let gt_mask #t a b =
| logand (gte_mask a b) (neq_mask a b) | false |
Lib.IntTypes.fst | Lib.IntTypes.lognot_lemma | val lognot_lemma: #t: inttype -> #l: secrecy_level ->
a: int_t t l ->
Lemma
(requires v a = 0 \/ v a = ones_v t)
(ensures (if v a = ones_v t then v (lognot a) == 0 else v (lognot a) == ones_v t)) | val lognot_lemma: #t: inttype -> #l: secrecy_level ->
a: int_t t l ->
Lemma
(requires v a = 0 \/ v a = ones_v t)
(ensures (if v a = ones_v t then v (lognot a) == 0 else v (lognot a) == ones_v t)) | 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)) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 86,
"end_line": 661,
"start_col": 0,
"start_line": 653
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | a: 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.lognot a) == 0
| _ -> Lib.IntTypes.v (Lib.IntTypes.lognot a) == Lib.IntTypes.ones_v t)
<:
Type0)) | FStar.Pervasives.Lemma | [
"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.lognot",
"Lib.IntTypes.u1",
"FStar.UInt.nth_lemma",
"Lib.IntTypes.bits",
"FStar.UInt.lognot",
"FStar.UInt.ones",
"FStar.UInt.zero",
"Prims.unit",
"FStar.UInt.lognot_lemma_1",
"FStar.Int.nth_lemma",
"FStar.Int.lognot",
"FStar.Int.ones",
"FStar.Int.zero"
] | [] | false | false | true | false | false | 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)) | false |
Lib.IntTypes.fst | Lib.IntTypes.lte_mask | val lte_mask: #t:inttype{unsigned t} -> int_t t SEC -> int_t t SEC -> int_t t SEC | 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 = logor (lt_mask a b) (eq_mask a b) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 55,
"end_line": 931,
"start_col": 0,
"start_line": 931
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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 | Prims.Tot | [
"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"
] | [] | false | false | false | false | false | let lte_mask #t a b =
| logor (lt_mask a b) (eq_mask a b) | false |
Lib.IntTypes.fst | Lib.IntTypes.shift_right_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))] | 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 =
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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 753,
"start_col": 0,
"start_line": 745
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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))] | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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) | false |
Lib.IntTypes.fst | Lib.IntTypes.gte_mask_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)] | 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 =
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
| _ -> () | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 905,
"start_col": 0,
"start_line": 896
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)] | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | false | let gte_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 /\ lognot (u1 1) == u1 0 /\
lognot (u1 0) == u1 1)
| _ -> () | false |
Lib.IntTypes.fst | Lib.IntTypes.gt_mask_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)] | 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 =
logand_zeros (gte_mask a b);
logand_ones (gte_mask a b) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 28,
"end_line": 929,
"start_col": 0,
"start_line": 927
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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)] | FStar.Pervasives.Lemma | [
"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"
] | [] | true | false | true | false | false | let gt_mask_lemma #t a b =
| logand_zeros (gte_mask a b);
logand_ones (gte_mask a b) | false |
Lib.IntTypes.fst | Lib.IntTypes.lt_mask_lemma | val lt_mask_lemma: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a < v b then v (lt_mask a b) == ones_v t
else v (lt_mask a b) == 0)
[SMTPat (lt_mask #t a b)] | val lt_mask_lemma: #t:inttype{unsigned t} -> a:int_t t SEC -> b:int_t t SEC -> Lemma
(if v a < v b then v (lt_mask a b) == ones_v t
else v (lt_mask a b) == 0)
[SMTPat (lt_mask #t 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 923,
"start_col": 0,
"start_line": 920
} | 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) | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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.lt_mask a b) == Lib.IntTypes.ones_v t
| _ -> Lib.IntTypes.v (Lib.IntTypes.lt_mask a b) == 0)
<:
Type0)) [SMTPat (Lib.IntTypes.lt_mask a b)] | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.inttype",
"Prims.b2t",
"Lib.IntTypes.unsigned",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"FStar.UInt.lognot_self",
"Lib.IntTypes.bits",
"Prims.unit",
"FStar.UInt.lognot_lemma_1",
"FStar.Pervasives.assert_norm",
"Prims.l_and",
"Prims.eq2",
"Lib.IntTypes.U1",
"Lib.IntTypes.lognot",
"Lib.IntTypes.u1"
] | [] | true | false | true | false | false | 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 |
Main.fst | Main.open_write_file | val open_write_file (s: string) : ML FStar.IO.fd_write | val open_write_file (s: string) : ML FStar.IO.fd_write | let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 28,
"end_line": 12,
"start_col": 0,
"start_line": 10
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2" | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.string -> FStar.All.ML FStar.IO.fd_write | FStar.All.ML | [
"ml"
] | [] | [
"Prims.string",
"FStar.IO.open_write_file",
"FStar.IO.fd_write",
"Prims.unit",
"FStar.IO.print_string",
"FStar.Printf.sprintf"
] | [] | false | true | false | false | false | let open_write_file (s: string) : ML FStar.IO.fd_write =
| FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s | false |
Lib.IntTypes.fst | Lib.IntTypes.div | 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 | 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 =
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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 44,
"end_line": 1037,
"start_col": 0,
"start_line": 1027
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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 | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
Main.fst | Main.left | val left (x: either 'a 'b) : ML 'a | val left (x: either 'a 'b) : ML 'a | let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left" | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 35,
"end_line": 40,
"start_col": 0,
"start_line": 36
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
} | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Ast.either 'a 'b -> FStar.All.ML 'a | FStar.All.ML | [
"ml"
] | [] | [
"Ast.either",
"FStar.All.failwith"
] | [] | false | true | false | false | false | let left (x: either 'a 'b) : ML 'a =
| match x with
| Inl x -> x
| _ -> failwith "Expected left" | false |
Main.fst | Main.initial_env | val initial_env: Prims.unit -> ML env | val initial_env: Prims.unit -> ML env | let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
} | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 1,
"end_line": 34,
"start_col": 0,
"start_line": 29
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
} | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Main.env | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"Main.Mkenv",
"Main.env",
"FStar.Pervasives.Native.tuple2",
"TranslateForInterpreter.translate_env",
"InterpreterTarget.env",
"FStar.Pervasives.Native.Mktuple2",
"InterpreterTarget.create_env",
"TranslateForInterpreter.initial_translate_env",
"TypeSizes.size_env",
"TypeSizes.initial_senv",
"GlobalEnv.global_env",
"Binding.initial_global_env"
] | [] | false | true | false | false | false | let initial_env () : ML env =
| {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env
=
(TranslateForInterpreter.initial_translate_env (), InterpreterTarget.create_env ())
} | false |
Main.fst | Main.translate_module | val translate_module (pa: opt_prune_actions) (en: env) (mname fn: string)
: ML (list Target.decl & list InterpreterTarget.decl & StaticAssertions.static_asserts & env) | val translate_module (pa: opt_prune_actions) (en: env) (mname fn: string)
: ML (list Target.decl & list InterpreterTarget.decl & StaticAssertions.static_asserts & env) | let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 4,
"end_line": 141,
"start_col": 0,
"start_line": 119
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | pa: Main.opt_prune_actions -> en: Main.env -> mname: Prims.string -> fn: Prims.string
-> FStar.All.ML
(((Prims.list Target.decl * Prims.list InterpreterTarget.decl) * StaticAssertions.static_asserts) *
Main.env) | FStar.All.ML | [
"ml"
] | [] | [
"Main.opt_prune_actions",
"Main.env",
"Prims.string",
"Prims.list",
"Ast.decl",
"StaticAssertions.static_asserts",
"Target.decl",
"InterpreterTarget.decl",
"FStar.Pervasives.Native.tuple2",
"TranslateForInterpreter.translate_env",
"InterpreterTarget.env",
"FStar.Pervasives.Native.Mktuple4",
"Main.Mkenv",
"Main.__proj__Mkenv__item__binding_env",
"Main.__proj__Mkenv__item__typesizes_env",
"FStar.Pervasives.Native.tuple4",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Pervasives.Native.Mktuple2",
"InterpreterTarget.translate_decls",
"TranslateForInterpreter.translate_decls",
"Main.__proj__Mkenv__item__translate_env",
"Main.parse_check_and_desugar"
] | [] | false | true | false | false | false | let translate_module (pa: opt_prune_actions) (en: env) (mname fn: string)
: ML (list Target.decl & list InterpreterTarget.decl & StaticAssertions.static_asserts & env) =
| let decls, static_asserts, en = parse_check_and_desugar pa en mname fn in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls, i_decls, static_asserts, en | false |
Main.fst | Main.right | val right (x: either 'a 'b) : ML 'b | val right (x: either 'a 'b) : ML 'b | let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right" | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 36,
"end_line": 46,
"start_col": 0,
"start_line": 42
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left" | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Ast.either 'a 'b -> FStar.All.ML 'b | FStar.All.ML | [
"ml"
] | [] | [
"Ast.either",
"FStar.All.failwith"
] | [] | false | true | false | false | false | let right (x: either 'a 'b) : ML 'b =
| match x with
| Inr x -> x
| _ -> failwith "Expected right" | false |
Main.fst | Main.parse_prog | val parse_prog (fn: string) : ML prog | val parse_prog (fn: string) : ML prog | let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn)) | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 116,
"end_line": 20,
"start_col": 0,
"start_line": 14
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | fn: Prims.string -> FStar.All.ML Ast.prog | FStar.All.ML | [
"ml"
] | [] | [
"Prims.string",
"Prims.list",
"Ast.decl",
"FStar.Pervasives.Native.option",
"Ast.type_refinement",
"FStar.Pervasives.Native.Mktuple2",
"Ast.prog",
"Prims.bool",
"FStar.Exn.raise",
"Ast.Error",
"FStar.Printf.sprintf",
"FStar.Pervasives.Native.uu___is_Some",
"FStar.List.tryFind",
"Ast.is_entrypoint_or_export",
"ParserDriver.parse"
] | [] | false | true | false | false | false | let parse_prog (fn: string) : ML prog =
| let decls, type_refinement_opt = ParserDriver.parse fn in
if decls |> List.tryFind is_entrypoint_or_export |> Some?
then decls, type_refinement_opt
else
raise (Error
(Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn
)) | false |
Lib.IntTypes.fst | Lib.IntTypes.eq | val eq: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | val eq: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | let eq #t x y =
x = y | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 7,
"end_line": 1068,
"start_col": 0,
"start_line": 1067
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | x: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> y: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.inttype",
"Lib.IntTypes.int_t",
"Lib.IntTypes.PUB",
"Prims.op_Equality",
"Prims.bool"
] | [] | false | false | false | false | false | let eq #t x y =
| x = y | false |
Lib.IntTypes.fst | Lib.IntTypes.gte_mask_logand_lemma | val gte_mask_logand_lemma: #t:inttype{unsigned 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` gte_mask a b) == v c
else v (c `logand` gte_mask a b) == 0)
[SMTPat (c `logand` gte_mask a b)] | val gte_mask_logand_lemma: #t:inttype{unsigned 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` gte_mask a b) == v c
else v (c `logand` gte_mask a b) == 0)
[SMTPat (c `logand` gte_mask a b)] | 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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 67,
"end_line": 916,
"start_col": 0,
"start_line": 907
} | 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
| _ -> () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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.gte_mask a b)) == Lib.IntTypes.v c
| _ -> Lib.IntTypes.v (Lib.IntTypes.logand c (Lib.IntTypes.gte_mask a b)) == 0)
<:
Type0)) [SMTPat (Lib.IntTypes.logand c (Lib.IntTypes.gte_mask a b))] | FStar.Pervasives.Lemma | [
"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",
"FStar.UInt.logand_commutative",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"Lib.IntTypes.gte_mask",
"Prims.unit",
"Lib.IntTypes.logand_ones",
"Lib.IntTypes.logand_zeros"
] | [] | false | false | true | false | false | 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) | false |
Main.fst | Main.process_file | val process_file
(en: env)
(fn modul: string)
(emit_fstar emit_output_types_defs: bool)
(all_modules: list string)
: ML env | val process_file
(en: env)
(fn modul: string)
(emit_fstar emit_output_types_defs: bool)
(all_modules: list string)
: ML env | let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules) | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 92,
"end_line": 382,
"start_col": 0,
"start_line": 374
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
en: Main.env ->
fn: Prims.string ->
modul: Prims.string ->
emit_fstar: Prims.bool ->
emit_output_types_defs: Prims.bool ->
all_modules: Prims.list Prims.string
-> FStar.All.ML Main.env | FStar.All.ML | [
"ml"
] | [] | [
"Main.env",
"Prims.string",
"Prims.bool",
"Prims.list",
"FStar.Pervasives.Native.fst",
"InterpreterTarget.decl",
"FStar.Pervasives.Native.tuple2",
"Main.process_file_gen",
"FStar.Pervasives.Native.None",
"Target.produce_everparse_error",
"Main.prune_actions"
] | [] | false | true | false | false | false | let process_file
(en: env)
(fn modul: string)
(emit_fstar emit_output_types_defs: bool)
(all_modules: list string)
: ML env =
| fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules) | false |
Main.fst | Main.emit_config_as_fstar_module | val emit_config_as_fstar_module: Prims.unit -> ML unit | val emit_config_as_fstar_module: Prims.unit -> ML unit | let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> () | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 13,
"end_line": 396,
"start_col": 0,
"start_line": 384
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules) | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"Config.config",
"Prims.string",
"FStar.IO.close_write_file",
"FStar.IO.write_string",
"FStar.IO.fd_write",
"Main.open_write_file",
"FStar.Printf.sprintf",
"Options.get_output_dir",
"Config.emit_config_as_fstar_module",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"Deps.get_config"
] | [] | false | true | false | false | false | let emit_config_as_fstar_module () : ML unit =
| match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file (Printf.sprintf "%s/%s.fst" (Options.get_output_dir ()) config_module_name)
in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> () | false |
Main.fst | Main.process_file_gen | val process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en: env)
(fn modul: string)
(emit_fstar emit_output_types_defs: bool)
(all_modules: list string)
: ML (env & list InterpreterTarget.decl) | val process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en: env)
(fn modul: string)
(emit_fstar emit_output_types_defs: bool)
(all_modules: list string)
: ML (env & list InterpreterTarget.decl) | let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 22,
"end_line": 372,
"start_col": 0,
"start_line": 344
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
produce_ep_error: Target.opt_produce_everparse_error ->
pa: Main.opt_prune_actions ->
en: Main.env ->
fn: Prims.string ->
modul: Prims.string ->
emit_fstar: Prims.bool ->
emit_output_types_defs: Prims.bool ->
all_modules: Prims.list Prims.string
-> FStar.All.ML (Main.env * Prims.list InterpreterTarget.decl) | FStar.All.ML | [
"ml"
] | [] | [
"Target.opt_produce_everparse_error",
"Main.opt_prune_actions",
"Main.env",
"Prims.string",
"Prims.bool",
"Prims.list",
"Target.decl",
"InterpreterTarget.decl",
"StaticAssertions.static_asserts",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.Native.tuple2",
"Main.Mkenv",
"Main.__proj__Mkenv__item__typesizes_env",
"Main.__proj__Mkenv__item__translate_env",
"GlobalEnv.global_env",
"Binding.finish_module",
"Main.__proj__Mkenv__item__binding_env",
"Prims.unit",
"TypeSizes.finish_module",
"Ast.ident'",
"Binding.get_exported_decls",
"Main.emit_entrypoint",
"Main.emit_fstar_code_for_interpreter",
"FStar.IO.print_string",
"FStar.Printf.sprintf",
"FStar.Pervasives.Native.tuple4",
"Main.translate_module"
] | [] | false | true | false | false | false | let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en: env)
(fn modul: string)
(emit_fstar emit_output_types_defs: bool)
(all_modules: list string)
: ML (env & list InterpreterTarget.decl) =
| let t_decls, interpreter_decls, static_asserts, en = translate_module pa en modul fn in
if emit_fstar
then
(emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{
en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env = en.translate_env
},
interpreter_decls | false |
Lib.IntTypes.fst | Lib.IntTypes.logxor_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) | 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) | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 38,
"end_line": 451,
"start_col": 0,
"start_line": 440
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | 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) | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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) | false |
Main.fst | Main.process_files_t | val process_files_t : Type0 | let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit)) | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 31,
"end_line": 422,
"start_col": 0,
"start_line": 418
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.string",
"Prims.bool",
"FStar.Pervasives.Native.option",
"Prims.unit"
] | [] | false | false | false | true | true | let process_files_t =
|
files_and_modules: list (string & string) ->
(emit_fstar: string -> ML bool) ->
emit_output_types_defs: bool
-> ML (option (unit -> ML unit)) | false |
|
Main.fst | Main.process_files_gen | val process_files_gen
(#env: Type)
(initial_env: (unit -> ML env))
(files_and_modules: list (string & string))
(emit_fstar: option (string -> ML bool))
(emit_output_types_defs: bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env | val process_files_gen
(#env: Type)
(initial_env: (unit -> ML env))
(files_and_modules: list (string & string))
(emit_fstar: option (string -> ML bool))
(emit_output_types_defs: bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env | let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 140,
"end_line": 416,
"start_col": 0,
"start_line": 398
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> () | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
initial_env: (_: Prims.unit -> FStar.All.ML env) ->
files_and_modules: Prims.list (Prims.string * Prims.string) ->
emit_fstar: FStar.Pervasives.Native.option (_: Prims.string -> FStar.All.ML Prims.bool) ->
emit_output_types_defs: Prims.bool ->
process_file:
(
_: env ->
_: Prims.string ->
_: Prims.string ->
_: Prims.bool ->
_: Prims.bool ->
_: Prims.list Prims.string
-> FStar.All.ML env)
-> FStar.All.ML env | FStar.All.ML | [
"ml"
] | [] | [
"Prims.unit",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.string",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.List.fold_left",
"FStar.Pervasives.Native.uu___is_Some",
"Main.emit_config_as_fstar_module",
"Options.get_batch",
"FStar.List.map",
"FStar.Pervasives.Native.snd",
"FStar.IO.print_string",
"FStar.Printf.sprintf",
"FStar.String.concat",
"FStar.Pervasives.Native.fst"
] | [] | false | true | false | false | false | let process_files_gen
(#env: Type)
(initial_env: (unit -> ML env))
(files_and_modules: list (string & string))
(emit_fstar: option (string -> ML bool))
(emit_output_types_defs: bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
| IO.print_string (Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then if Options.get_batch () then emit_config_as_fstar_module ();
files_and_modules |>
List.fold_left (fun env (fn, modul) ->
process_file env
fn
modul
(match emit_fstar with
| Some f -> f modul
| _ -> false)
emit_output_types_defs
all_modules)
env | false |
Lib.IntTypes.fst | Lib.IntTypes.div_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))] | 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 =
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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 1045,
"start_col": 0,
"start_line": 1039
} | 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 | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false |
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))] | FStar.Pervasives.Lemma | [
"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"
] | [] | false | false | true | false | 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 | false |
Main.fst | Main.process_files | val process_files:process_files_t | val process_files:process_files_t | let process_files : process_files_t = fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen
initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file
|> ignore;
(Some (fun _ -> ())) | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 22,
"end_line": 432,
"start_col": 0,
"start_line": 424
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env
let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit)) | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Main.process_files_t | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.string",
"Prims.bool",
"FStar.Pervasives.Native.Some",
"Prims.unit",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.ignore",
"Main.env",
"Main.process_files_gen",
"Main.initial_env",
"Main.process_file"
] | [] | false | false | false | true | false | let process_files:process_files_t =
| fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file |>
ignore;
(Some (fun _ -> ())) | false |
Main.fst | Main.build_test_exe | val build_test_exe (out_dir: string) : ML unit | val build_test_exe (out_dir: string) : ML unit | let build_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
OS.run_cmd "make" ["-C"; out_dir; "-f"; "Makefile.basic"; "USER_TARGET=test.exe"; "USER_CFLAGS=-Wno-type-limits"]
end | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 475,
"start_col": 0,
"start_line": 468
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env
let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit))
let process_files : process_files_t = fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen
initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file
|> ignore;
(Some (fun _ -> ()))
let process_file_for_z3
(out: string -> ML unit)
(en_accu:(env & Z3TestGen.prog))
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & Z3TestGen.prog) =
let (en, accu) = en_accu in
let (en, interpreter_decls) = process_file_gen (Some Target.ProduceEverParseError) (Some PruneActions) en fn modul emit_fstar emit_output_types_defs all_modules in
let accu = Z3TestGen.produce_decls out accu interpreter_decls in
(en, accu)
let process_files_for_z3
(out: string -> ML unit)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
: ML Z3TestGen.prog =
out Z3TestGen.prelude;
process_files_gen
(fun _ -> initial_env (), [])
files_and_modules
emit_fstar
emit_output_types_defs
(process_file_for_z3 out)
|> snd
let produce_z3
(files_and_modules:list (string & string))
: ML unit
= ignore (process_files_for_z3 FStar.IO.print_string files_and_modules None false) | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | out_dir: Prims.string -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.string",
"OS.run_cmd",
"Prims.Cons",
"Prims.Nil",
"Prims.unit",
"Prims.bool",
"Prims.op_Negation",
"Options.get_skip_c_makefiles"
] | [] | false | true | false | false | false | let build_test_exe (out_dir: string) : ML unit =
| if not (Options.get_skip_c_makefiles ())
then
OS.run_cmd "make"
["-C"; out_dir; "-f"; "Makefile.basic"; "USER_TARGET=test.exe"; "USER_CFLAGS=-Wno-type-limits"] | false |
Lib.IntTypes.fst | Lib.IntTypes.lte | val lte: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | val lte: #t:inttype -> int_t t PUB -> int_t t PUB -> bool | 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 | {
"file_name": "lib/Lib.IntTypes.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 1104,
"start_col": 0,
"start_line": 1092
} | 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 = () | {
"checked_file": "/",
"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"
} | [
{
"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
}
] | {
"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"
} | false | x: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> y: Lib.IntTypes.int_t t Lib.IntTypes.PUB -> Prims.bool | Prims.Tot | [
"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"
] | [] | false | false | false | false | 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 | false |
Main.fst | Main.build_and_run_test_exe | val build_and_run_test_exe (out_dir: string) : ML unit | val build_and_run_test_exe (out_dir: string) : ML unit | let build_and_run_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
build_test_exe out_dir;
OS.run_cmd (OS.concat out_dir "test.exe") []
end | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 485,
"start_col": 0,
"start_line": 477
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env
let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit))
let process_files : process_files_t = fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen
initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file
|> ignore;
(Some (fun _ -> ()))
let process_file_for_z3
(out: string -> ML unit)
(en_accu:(env & Z3TestGen.prog))
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & Z3TestGen.prog) =
let (en, accu) = en_accu in
let (en, interpreter_decls) = process_file_gen (Some Target.ProduceEverParseError) (Some PruneActions) en fn modul emit_fstar emit_output_types_defs all_modules in
let accu = Z3TestGen.produce_decls out accu interpreter_decls in
(en, accu)
let process_files_for_z3
(out: string -> ML unit)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
: ML Z3TestGen.prog =
out Z3TestGen.prelude;
process_files_gen
(fun _ -> initial_env (), [])
files_and_modules
emit_fstar
emit_output_types_defs
(process_file_for_z3 out)
|> snd
let produce_z3
(files_and_modules:list (string & string))
: ML unit
= ignore (process_files_for_z3 FStar.IO.print_string files_and_modules None false)
let build_test_exe
(out_dir: string)
: ML unit
=
if not (Options.get_skip_c_makefiles ())
then begin
OS.run_cmd "make" ["-C"; out_dir; "-f"; "Makefile.basic"; "USER_TARGET=test.exe"; "USER_CFLAGS=-Wno-type-limits"]
end | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | out_dir: Prims.string -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.string",
"OS.run_cmd",
"OS.concat",
"Prims.Nil",
"Prims.unit",
"Main.build_test_exe",
"Prims.bool",
"Prims.op_Negation",
"Options.get_skip_c_makefiles"
] | [] | false | true | false | false | false | let build_and_run_test_exe (out_dir: string) : ML unit =
| if not (Options.get_skip_c_makefiles ())
then
(build_test_exe out_dir;
OS.run_cmd (OS.concat out_dir "test.exe") []) | false |
Main.fst | Main.produce_z3 | val produce_z3 (files_and_modules: list (string & string)) : ML unit | val produce_z3 (files_and_modules: list (string & string)) : ML unit | let produce_z3
(files_and_modules:list (string & string))
: ML unit
= ignore (process_files_for_z3 FStar.IO.print_string files_and_modules None false) | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 82,
"end_line": 466,
"start_col": 0,
"start_line": 463
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env
let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit))
let process_files : process_files_t = fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen
initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file
|> ignore;
(Some (fun _ -> ()))
let process_file_for_z3
(out: string -> ML unit)
(en_accu:(env & Z3TestGen.prog))
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & Z3TestGen.prog) =
let (en, accu) = en_accu in
let (en, interpreter_decls) = process_file_gen (Some Target.ProduceEverParseError) (Some PruneActions) en fn modul emit_fstar emit_output_types_defs all_modules in
let accu = Z3TestGen.produce_decls out accu interpreter_decls in
(en, accu)
let process_files_for_z3
(out: string -> ML unit)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
: ML Z3TestGen.prog =
out Z3TestGen.prelude;
process_files_gen
(fun _ -> initial_env (), [])
files_and_modules
emit_fstar
emit_output_types_defs
(process_file_for_z3 out)
|> snd | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | files_and_modules: Prims.list (Prims.string * Prims.string) -> FStar.All.ML Prims.unit | FStar.All.ML | [
"ml"
] | [] | [
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"Prims.string",
"FStar.Pervasives.ignore",
"Z3TestGen.prog",
"Prims.unit",
"Main.process_files_for_z3",
"FStar.IO.print_string",
"FStar.Pervasives.Native.None",
"Prims.bool"
] | [] | false | true | false | false | false | let produce_z3 (files_and_modules: list (string & string)) : ML unit =
| ignore (process_files_for_z3 FStar.IO.print_string files_and_modules None false) | false |
Main.fst | Main.process_file_for_z3 | val process_file_for_z3
(out: (string -> ML unit))
(en_accu: (env & Z3TestGen.prog))
(fn modul: string)
(emit_fstar emit_output_types_defs: bool)
(all_modules: list string)
: ML (env & Z3TestGen.prog) | val process_file_for_z3
(out: (string -> ML unit))
(en_accu: (env & Z3TestGen.prog))
(fn modul: string)
(emit_fstar emit_output_types_defs: bool)
(all_modules: list string)
: ML (env & Z3TestGen.prog) | let process_file_for_z3
(out: string -> ML unit)
(en_accu:(env & Z3TestGen.prog))
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & Z3TestGen.prog) =
let (en, accu) = en_accu in
let (en, interpreter_decls) = process_file_gen (Some Target.ProduceEverParseError) (Some PruneActions) en fn modul emit_fstar emit_output_types_defs all_modules in
let accu = Z3TestGen.produce_decls out accu interpreter_decls in
(en, accu) | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 12,
"end_line": 446,
"start_col": 0,
"start_line": 434
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env
let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit))
let process_files : process_files_t = fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen
initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file
|> ignore;
(Some (fun _ -> ())) | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
out: (_: Prims.string -> FStar.All.ML Prims.unit) ->
en_accu: (Main.env * Z3TestGen.prog) ->
fn: Prims.string ->
modul: Prims.string ->
emit_fstar: Prims.bool ->
emit_output_types_defs: Prims.bool ->
all_modules: Prims.list Prims.string
-> FStar.All.ML (Main.env * Z3TestGen.prog) | FStar.All.ML | [
"ml"
] | [] | [
"Prims.string",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"Main.env",
"Z3TestGen.prog",
"Prims.bool",
"Prims.list",
"InterpreterTarget.decl",
"FStar.Pervasives.Native.Mktuple2",
"Z3TestGen.produce_decls",
"Main.process_file_gen",
"FStar.Pervasives.Native.Some",
"Target.produce_everparse_error",
"Target.ProduceEverParseError",
"Main.prune_actions",
"Main.PruneActions"
] | [] | false | true | false | false | false | let process_file_for_z3
(out: (string -> ML unit))
(en_accu: (env & Z3TestGen.prog))
(fn modul: string)
(emit_fstar emit_output_types_defs: bool)
(all_modules: list string)
: ML (env & Z3TestGen.prog) =
| let en, accu = en_accu in
let en, interpreter_decls =
process_file_gen (Some Target.ProduceEverParseError)
(Some PruneActions)
en
fn
modul
emit_fstar
emit_output_types_defs
all_modules
in
let accu = Z3TestGen.produce_decls out accu interpreter_decls in
(en, accu) | false |
Main.fst | Main.process_files_for_z3 | val process_files_for_z3
(out: (string -> ML unit))
(files_and_modules: list (string & string))
(emit_fstar: option (string -> ML bool))
(emit_output_types_defs: bool)
: ML Z3TestGen.prog | val process_files_for_z3
(out: (string -> ML unit))
(files_and_modules: list (string & string))
(emit_fstar: option (string -> ML bool))
(emit_output_types_defs: bool)
: ML Z3TestGen.prog | let process_files_for_z3
(out: string -> ML unit)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
: ML Z3TestGen.prog =
out Z3TestGen.prelude;
process_files_gen
(fun _ -> initial_env (), [])
files_and_modules
emit_fstar
emit_output_types_defs
(process_file_for_z3 out)
|> snd | {
"file_name": "src/3d/Main.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 8,
"end_line": 461,
"start_col": 0,
"start_line": 448
} | module Main
open FStar.IO
open FStar.All
open Ast
open ParserDriver
module T = Target
open FStar.ST
#push-options "--z3rlimit_factor 2"
let open_write_file (s:string) : ML FStar.IO.fd_write =
FStar.IO.print_string (FStar.Printf.sprintf "Writing file %s\n" s);
FStar.IO.open_write_file s
let parse_prog (fn:string) : ML prog =
let decls, type_refinement_opt = ParserDriver.parse fn in
if decls
|> List.tryFind is_entrypoint_or_export
|> Some?
then decls, type_refinement_opt
else raise (Error (Printf.sprintf "File %s does not have an entry point or an exported definition, exiting\n" fn))
noeq
type env = {
binding_env : Binding.global_env;
typesizes_env : TypeSizes.size_env;
translate_env : (TranslateForInterpreter.translate_env & InterpreterTarget.env);
}
let initial_env () : ML env = {
binding_env = Binding.initial_global_env ();
typesizes_env = TypeSizes.initial_senv ();
translate_env =
(TranslateForInterpreter.initial_translate_env(), InterpreterTarget.create_env());
}
let left (x:either 'a 'b)
: ML 'a
= match x with
| Inl x -> x
| _ -> failwith "Expected left"
let right (x:either 'a 'b)
: ML 'b
= match x with
| Inr x -> x
| _ -> failwith "Expected right"
type prune_actions = | PruneActions
type opt_prune_actions = option prune_actions
let parse_check_and_desugar (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Ast.decl &
StaticAssertions.static_asserts &
env) =
Options.debug_print_string (FStar.Printf.sprintf "Processing file: %s\nModule name: %s\n" fn mname);
let decls, refinement =
let p = parse_prog fn in
if pa = Some PruneActions
then prog_prune_actions p
else p
in
Options.debug_print_string "=============After parsing=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, refinement = Desugar.desugar en.binding_env mname (decls, refinement) in
Options.debug_print_string "=============After desugaring=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls, benv = Binding.bind_decls en.binding_env decls in
Options.debug_print_string "=============After binding=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
if Options.get_json()
then (
IO.print_string (JSON.prog_to_json (decls, refinement));
IO.print_string "\n"
);
let decls = BitFields.eliminate_decls benv decls in
Options.debug_print_string "=============After bitflds=============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = TypeSizes.size_of_decls benv en.typesizes_env decls in
Options.debug_print_string "=============Finished typesizes pass=============\n";
let static_asserts = StaticAssertions.compute_static_asserts benv en.typesizes_env refinement in
Options.debug_print_string "=============Finished static asserts pass=============\n";
let decls = Simplify.simplify_prog benv en.typesizes_env decls in
Options.debug_print_string "=============After simplify============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let decls = InlineSingletonRecords.simplify_prog decls in
Options.debug_print_string "=============After inline singletons============\n";
Options.debug_print_string (print_decls decls);
Options.debug_print_string "\n";
let en = {
en with
binding_env = benv
} in
decls,
static_asserts,
en
let translate_module (pa: opt_prune_actions) (en:env) (mname:string) (fn:string)
: ML (list Target.decl &
list InterpreterTarget.decl &
StaticAssertions.static_asserts &
env) =
let decls, static_asserts, en =
parse_check_and_desugar pa en mname fn
in
let t_decls, i_decls, tenv =
let env, env' = en.translate_env in
let decls, env =
TranslateForInterpreter.translate_decls en.binding_env en.typesizes_env env decls
in
let tds = InterpreterTarget.translate_decls env' decls in
decls, tds, (env, env')
in
let en = { en with translate_env = tenv } in
t_decls,
i_decls,
static_asserts,
en
let emit_fstar_code_for_interpreter (en:env)
(modul:string)
(tds:list T.decl)
(itds:list InterpreterTarget.decl)
(all_modules:list string)
: ML unit
= let _, en = en.translate_env in
let impl, iface =
InterpreterTarget.print_decls en modul itds
in
let has_external_types = T.has_output_types tds || T.has_extern_types tds in
if has_external_types
then begin
let external_types_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalTypes.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_types_fsti_file (Target.print_external_types_fstar_interpreter modul tds);
FStar.IO.close_write_file external_types_fsti_file
end;
let has_external_api = T.has_external_api tds in
if has_external_api
then begin
let external_api_fsti_file =
open_write_file
(Printf.sprintf "%s/%s.ExternalAPI.fsti" (Options.get_output_dir ()) modul) in
FStar.IO.write_string external_api_fsti_file (Target.print_external_api_fstar_interpreter modul tds);
FStar.IO.close_write_file external_api_fsti_file
end;
let maybe_open_external_api =
if has_external_api
then Printf.sprintf "open %s.ExternalAPI" modul
else ""
in
let module_prefix =
FStar.Printf.sprintf "module %s\n\
open EverParse3d.Prelude\n\
open EverParse3d.Actions.All\n\
open EverParse3d.Interpreter\n\
%s\n\
module T = FStar.Tactics\n\
module A = EverParse3d.Actions.All\n\
module P = EverParse3d.Prelude\n\
#push-options \"--fuel 0 --ifuel 0\"\n\
#push-options \"--using_facts_from 'Prims FStar.UInt FStar.UInt8 \
FStar.UInt16 FStar.UInt32 FStar.UInt64 \
EverParse3d FStar.Int.Cast %s'\"\n"
modul maybe_open_external_api (all_modules |> String.concat " ")
in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fst_file module_prefix;
FStar.IO.write_string fst_file impl;
FStar.IO.close_write_file fst_file;
let fsti_file =
open_write_file
(Printf.sprintf "%s/%s.fsti"
(Options.get_output_dir())
modul) in
FStar.IO.write_string fsti_file module_prefix;
FStar.IO.write_string fsti_file iface;
FStar.IO.close_write_file fsti_file;
()
let emit_entrypoint (produce_ep_error: Target.opt_produce_everparse_error)
(en:env) (modul:string) (t_decls:list Target.decl)
(static_asserts:StaticAssertions.static_asserts)
(emit_output_types_defs:bool)
: ML unit =
//print wrapper only if there is an entrypoint
if List.tryFind (fun (d, _) ->
let open Target in
match d with
| Type_decl td -> td.decl_name.td_entrypoint
| _ -> false) t_decls |> Some?
then begin
let wrapper_header, wrapper_impl = Target.print_c_entry produce_ep_error modul en.binding_env t_decls in
let c_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_file wrapper_impl;
FStar.IO.close_write_file c_file;
let h_file =
open_write_file
(Printf.sprintf "%s/%sWrapper.h"
(Options.get_output_dir())
modul) in
FStar.IO.write_string h_file wrapper_header;
FStar.IO.close_write_file h_file
end;
let has_output_types = T.has_output_types t_decls in
let has_out_exprs = T.has_output_type_exprs t_decls in
let has_extern_types = T.has_extern_types t_decls in
(*
* If there are output types in the module
* and emit_output_types_defs flag is set,
* then emit output type definitions in M_OutputTypesDefs.h
*)
if emit_output_types_defs
then begin
if has_output_types
then begin
let output_types_defs_file = open_write_file
(Printf.sprintf "%s/%s_OutputTypesDefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string output_types_defs_file (Target.print_output_types_defs modul t_decls);
FStar.IO.close_write_file output_types_defs_file
end;
(*
* Optimization: If the module has no extern types,
* then M_ExternalTypedefs.h, that we require the programmer to provide,
* only contains output type defs
*
* So generate M_ExteralTypedefs.h, with #include of M_OutputTypesDefs.h
*)
if has_output_types && not has_extern_types
then begin
let extern_typedefs_file = open_write_file
(Printf.sprintf "%s/%s_ExternalTypedefs.h"
(Options.get_output_dir ())
modul) in
FStar.IO.write_string extern_typedefs_file
(Printf.sprintf
"#ifndef __%s_ExternalTypedefs_H\n\
#define __%s_ExternalTypedefs_H\n
#if defined(__cplusplus)\n\
extern \"C\" {\n\
#endif\n\n\n\
%s#include \"%s_OutputTypesDefs.h\"\n\n\
#if defined(__cplusplus)\n\
}\n\
#endif\n\n\
#define __%s_ExternalTypedefs_H_DEFINED\n\
#endif\n"
modul
modul
(Options.make_includes ())
modul
modul);
FStar.IO.close_write_file extern_typedefs_file
end
end;
// (*
// * Optimization: If M only has extern functions, and no types,
// * then the external typedefs file is trivially empty
// *)
// if has_extern_fns && not (has_out_exprs || has_extern_types)
// then begin
// let extern_typedefs_file = open_write_file
// (Printf.sprintf "%s/%s_ExternalTypedefs.h"
// (Options.get_output_dir ())
// modul) in
// FStar.IO.write_string extern_typedefs_file "\n";
// FStar.IO.close_write_file extern_typedefs_file
// end;
if has_out_exprs
then begin
let output_types_c_file =
open_write_file
(Printf.sprintf "%s/%s_OutputTypes.c" (Options.get_output_dir ()) modul) in
FStar.IO.write_string output_types_c_file (Target.print_out_exprs_c modul t_decls);
FStar.IO.close_write_file output_types_c_file
end;
if StaticAssertions.has_static_asserts static_asserts then begin
let c_static_asserts_file =
open_write_file
(Printf.sprintf "%s/%sStaticAssertions.c"
(Options.get_output_dir())
modul) in
FStar.IO.write_string c_static_asserts_file (StaticAssertions.print_static_asserts static_asserts);
FStar.IO.close_write_file c_static_asserts_file
end
let process_file_gen
(produce_ep_error: Target.opt_produce_everparse_error)
(pa: opt_prune_actions)
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & list InterpreterTarget.decl) =
let t_decls, interpreter_decls, static_asserts, en =
translate_module pa en modul fn
in
if emit_fstar
then (
emit_fstar_code_for_interpreter en modul t_decls interpreter_decls all_modules;
emit_entrypoint produce_ep_error en modul t_decls static_asserts emit_output_types_defs
)
else IO.print_string (Printf.sprintf "Not emitting F* code for %s\n" fn);
let ds = Binding.get_exported_decls en.binding_env modul in
TypeSizes.finish_module en.typesizes_env modul ds;
{ en with
binding_env = Binding.finish_module en.binding_env modul;
translate_env =
en.translate_env;
}, interpreter_decls
let process_file
(en:env)
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs: bool)
(all_modules:list string)
: ML env =
fst (process_file_gen None None en fn modul emit_fstar emit_output_types_defs all_modules)
let emit_config_as_fstar_module ()
: ML unit
= match Deps.get_config () with
| Some (cfg, config_module_name) ->
let fst_file_contents = Config.emit_config_as_fstar_module config_module_name cfg in
let fst_file =
open_write_file
(Printf.sprintf "%s/%s.fst"
(Options.get_output_dir())
config_module_name) in
FStar.IO.write_string fst_file fst_file_contents;
FStar.IO.close_write_file fst_file
| _ -> ()
let process_files_gen
(#env: Type)
(initial_env: unit -> ML env)
(files_and_modules:list (string & string))
(emit_fstar:option (string -> ML bool))
(emit_output_types_defs:bool)
(process_file: (env -> string -> string -> bool -> bool -> list string -> ML env))
: ML env =
IO.print_string
(Printf.sprintf "Processing files: %s\n"
(List.map fst files_and_modules |> String.concat " "));
let all_modules = List.map snd files_and_modules in
let env = initial_env () in
if Some? emit_fstar then
if Options.get_batch() then emit_config_as_fstar_module();
files_and_modules
|> List.fold_left (fun env (fn, modul) ->
process_file env fn modul (match emit_fstar with Some f -> f modul | _ -> false) emit_output_types_defs all_modules) env
let process_files_t =
(files_and_modules:list (string & string)) ->
(emit_fstar:string -> ML bool) ->
(emit_output_types_defs:bool) ->
ML (option (unit -> ML unit))
let process_files : process_files_t = fun files_and_modules emit_fstar emit_output_types_defs ->
process_files_gen
initial_env
files_and_modules
(Some emit_fstar)
emit_output_types_defs
process_file
|> ignore;
(Some (fun _ -> ()))
let process_file_for_z3
(out: string -> ML unit)
(en_accu:(env & Z3TestGen.prog))
(fn:string)
(modul:string)
(emit_fstar:bool)
(emit_output_types_defs:bool)
(all_modules:list string)
: ML (env & Z3TestGen.prog) =
let (en, accu) = en_accu in
let (en, interpreter_decls) = process_file_gen (Some Target.ProduceEverParseError) (Some PruneActions) en fn modul emit_fstar emit_output_types_defs all_modules in
let accu = Z3TestGen.produce_decls out accu interpreter_decls in
(en, accu) | {
"checked_file": "/",
"dependencies": [
"Z3TestGen.fst.checked",
"Z3.fsti.checked",
"TypeSizes.fsti.checked",
"TranslateForInterpreter.fsti.checked",
"Target.fsti.checked",
"StaticAssertions.fst.checked",
"Simplify.fsti.checked",
"prims.fst.checked",
"ParserDriver.fsti.checked",
"OS.fsti.checked",
"Options.fsti.checked",
"JSON.fsti.checked",
"InterpreterTarget.fsti.checked",
"InlineSingletonRecords.fst.checked",
"HashingOptions.fst.checked",
"GenMakefile.fsti.checked",
"FStar.String.fsti.checked",
"FStar.ST.fst.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.IO.fst.checked",
"FStar.All.fst.checked",
"Desugar.fst.checked",
"Deps.fsti.checked",
"Config.fst.checked",
"BitFields.fst.checked",
"Binding.fsti.checked",
"Batch.fsti.checked",
"Ast.fst.checked"
],
"interface_file": false,
"source_file": "Main.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.ST",
"short_module": null
},
{
"abbrev": true,
"full_module": "Target",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "ParserDriver",
"short_module": null
},
{
"abbrev": false,
"full_module": "Ast",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.IO",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 2,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
out: (_: Prims.string -> FStar.All.ML Prims.unit) ->
files_and_modules: Prims.list (Prims.string * Prims.string) ->
emit_fstar: FStar.Pervasives.Native.option (_: Prims.string -> FStar.All.ML Prims.bool) ->
emit_output_types_defs: Prims.bool
-> FStar.All.ML Z3TestGen.prog | FStar.All.ML | [
"ml"
] | [] | [
"Prims.string",
"Prims.unit",
"Prims.list",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.option",
"Prims.bool",
"FStar.Pervasives.Native.snd",
"Main.env",
"Z3TestGen.prog_def",
"Z3TestGen.prog",
"Main.process_files_gen",
"FStar.Pervasives.Native.Mktuple2",
"Prims.Nil",
"Main.initial_env",
"Main.process_file_for_z3",
"Z3TestGen.prelude"
] | [] | false | true | false | false | false | let process_files_for_z3
(out: (string -> ML unit))
(files_and_modules: list (string & string))
(emit_fstar: option (string -> ML bool))
(emit_output_types_defs: bool)
: ML Z3TestGen.prog =
| out Z3TestGen.prelude;
process_files_gen (fun _ -> initial_env (), [])
files_and_modules
emit_fstar
emit_output_types_defs
(process_file_for_z3 out) |>
snd | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.