effect
stringclasses 48
values | original_source_type
stringlengths 0
23k
| opens_and_abbrevs
listlengths 2
92
| isa_cross_project_example
bool 1
class | source_definition
stringlengths 9
57.9k
| partial_definition
stringlengths 7
23.3k
| is_div
bool 2
classes | is_type
null | is_proof
bool 2
classes | completed_definiton
stringlengths 1
250k
| dependencies
dict | effect_flags
sequencelengths 0
2
| ideal_premises
sequencelengths 0
236
| mutual_with
sequencelengths 0
11
| file_context
stringlengths 0
407k
| interleaved
bool 1
class | is_simply_typed
bool 2
classes | file_name
stringlengths 5
48
| vconfig
dict | is_simple_lemma
null | source_type
stringlengths 10
23k
| proof_features
sequencelengths 0
1
| name
stringlengths 8
95
| source
dict | verbose_type
stringlengths 1
7.42k
| source_range
dict |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let a_spec (a:fixed_len_alg) (i:nat) =
Seq.lseq uint8 (if i = 0 then 0 else hash_length a) | let a_spec (a: fixed_len_alg) (i: nat) = | false | null | false | Seq.lseq uint8 (if i = 0 then 0 else hash_length a) | {
"checked_file": "Spec.Agile.HKDF.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked"
],
"interface_file": true,
"source_file": "Spec.Agile.HKDF.fst"
} | [
"total"
] | [
"Spec.Hash.Definitions.fixed_len_alg",
"FStar.Integers.nat",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Prims.op_Equality",
"Prims.int",
"Prims.bool",
"Spec.Hash.Definitions.hash_length",
"Lib.IntTypes.size_nat"
] | [] | module Spec.Agile.HKDF
open FStar.Integers
open Spec.Hash.Definitions
/// FUNCTIONAL SPECIFICATION:
///
/// * extraction is just HMAC using the salt as key and the input
/// keying materials as text.
///
/// * expansion does its own formatting of input key materials.
open FStar.Seq
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
let extract = Spec.Agile.HMAC.hmac
module Seq = Lib.Sequence
open Lib.IntTypes
/// HKDF-Expand(PRK, info, L)
///
/// N = ceil(L/HashLen)
/// T = T(1) | T(2) | T(3) | ... | T(N)
/// OKM = first L octets of T
///
/// where:
/// T(0) = empty string (zero length)
/// T(1) = HMAC-Hash(PRK, T(0) | info | 0x01)
/// T(2) = HMAC-Hash(PRK, T(1) | info | 0x02)
/// T(3) = HMAC-Hash(PRK, T(2) | info | 0x03)
///
/// See https://tools.ietf.org/html/rfc5869#section-2.3
/// The type of T(i) is [a_spec a i] | false | true | Spec.Agile.HKDF.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val a_spec : a: Spec.Hash.Definitions.fixed_len_alg -> i: FStar.Integers.nat -> Type0 | [] | Spec.Agile.HKDF.a_spec | {
"file_name": "specs/Spec.Agile.HKDF.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Spec.Hash.Definitions.fixed_len_alg -> i: FStar.Integers.nat -> Type0 | {
"end_col": 53,
"end_line": 38,
"start_col": 2,
"start_line": 38
} |
|
Prims.Pure | val extract:
a: fixed_len_alg ->
key: bytes ->
data: bytes ->
Pure (lbytes (hash_length a))
(requires
Spec.Agile.HMAC.keysized a (Seq.length key) /\
extract_ikm_length_pred a (Seq.length data))
(ensures fun _ -> True) | [
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let extract = Spec.Agile.HMAC.hmac | val extract:
a: fixed_len_alg ->
key: bytes ->
data: bytes ->
Pure (lbytes (hash_length a))
(requires
Spec.Agile.HMAC.keysized a (Seq.length key) /\
extract_ikm_length_pred a (Seq.length data))
(ensures fun _ -> True)
let extract = | false | null | false | Spec.Agile.HMAC.hmac | {
"checked_file": "Spec.Agile.HKDF.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked"
],
"interface_file": true,
"source_file": "Spec.Agile.HKDF.fst"
} | [] | [
"Spec.Agile.HMAC.hmac"
] | [] | module Spec.Agile.HKDF
open FStar.Integers
open Spec.Hash.Definitions
/// FUNCTIONAL SPECIFICATION:
///
/// * extraction is just HMAC using the salt as key and the input
/// keying materials as text.
///
/// * expansion does its own formatting of input key materials.
open FStar.Seq
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50" | false | false | Spec.Agile.HKDF.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val extract:
a: fixed_len_alg ->
key: bytes ->
data: bytes ->
Pure (lbytes (hash_length a))
(requires
Spec.Agile.HMAC.keysized a (Seq.length key) /\
extract_ikm_length_pred a (Seq.length data))
(ensures fun _ -> True) | [] | Spec.Agile.HKDF.extract | {
"file_name": "specs/Spec.Agile.HKDF.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Spec.Hash.Definitions.fixed_len_alg ->
key: Spec.Hash.Definitions.bytes ->
data: Spec.Hash.Definitions.bytes
-> Prims.Pure (Spec.Agile.HKDF.lbytes (Spec.Hash.Definitions.hash_length a)) | {
"end_col": 34,
"end_line": 17,
"start_col": 14,
"start_line": 17
} |
Prims.Pure | val expand_loop:
a:fixed_len_alg
-> prk:bytes
-> info:bytes
-> n:nat
-> i:nat{i < n}
-> a_spec a i
-> Pure (a_spec a (i + 1) & Seq.lseq uint8 (hash_length a))
(requires
hash_length a <= Seq.length prk /\
HMAC.keysized a (Seq.length prk) /\
(hash_length a + Seq.length info + 1 + block_length a) `less_than_max_input_length` a /\
n <= 255)
(ensures fun _ -> True) | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let expand_loop a prk info n i tag =
let t = Spec.Agile.HMAC.hmac a prk (tag @| info @| Seq.create 1 (u8 (i + 1))) in
t, t | val expand_loop:
a:fixed_len_alg
-> prk:bytes
-> info:bytes
-> n:nat
-> i:nat{i < n}
-> a_spec a i
-> Pure (a_spec a (i + 1) & Seq.lseq uint8 (hash_length a))
(requires
hash_length a <= Seq.length prk /\
HMAC.keysized a (Seq.length prk) /\
(hash_length a + Seq.length info + 1 + block_length a) `less_than_max_input_length` a /\
n <= 255)
(ensures fun _ -> True)
let expand_loop a prk info n i tag = | false | null | false | let t = Spec.Agile.HMAC.hmac a prk (tag @| info @| Seq.create 1 (u8 (i + 1))) in
t, t | {
"checked_file": "Spec.Agile.HKDF.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked"
],
"interface_file": true,
"source_file": "Spec.Agile.HKDF.fst"
} | [] | [
"Spec.Hash.Definitions.fixed_len_alg",
"Spec.Hash.Definitions.bytes",
"FStar.Integers.nat",
"Prims.b2t",
"FStar.Integers.op_Less",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"Spec.Agile.HKDF.a_spec",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Integers.op_Plus",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint8",
"Spec.Hash.Definitions.hash_length",
"Spec.Agile.HMAC.lbytes",
"Spec.Agile.HMAC.hmac",
"FStar.Seq.Base.op_At_Bar",
"Lib.Sequence.create",
"Lib.IntTypes.u8",
"FStar.Pervasives.Native.tuple2"
] | [] | module Spec.Agile.HKDF
open FStar.Integers
open Spec.Hash.Definitions
/// FUNCTIONAL SPECIFICATION:
///
/// * extraction is just HMAC using the salt as key and the input
/// keying materials as text.
///
/// * expansion does its own formatting of input key materials.
open FStar.Seq
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
let extract = Spec.Agile.HMAC.hmac
module Seq = Lib.Sequence
open Lib.IntTypes
/// HKDF-Expand(PRK, info, L)
///
/// N = ceil(L/HashLen)
/// T = T(1) | T(2) | T(3) | ... | T(N)
/// OKM = first L octets of T
///
/// where:
/// T(0) = empty string (zero length)
/// T(1) = HMAC-Hash(PRK, T(0) | info | 0x01)
/// T(2) = HMAC-Hash(PRK, T(1) | info | 0x02)
/// T(3) = HMAC-Hash(PRK, T(2) | info | 0x03)
///
/// See https://tools.ietf.org/html/rfc5869#section-2.3
/// The type of T(i) is [a_spec a i]
let a_spec (a:fixed_len_alg) (i:nat) =
Seq.lseq uint8 (if i = 0 then 0 else hash_length a)
/// The main loop that computes T(i)
val expand_loop:
a:fixed_len_alg
-> prk:bytes
-> info:bytes
-> n:nat
-> i:nat{i < n}
-> a_spec a i
-> Pure (a_spec a (i + 1) & Seq.lseq uint8 (hash_length a))
(requires
hash_length a <= Seq.length prk /\
HMAC.keysized a (Seq.length prk) /\
(hash_length a + Seq.length info + 1 + block_length a) `less_than_max_input_length` a /\
n <= 255) | false | false | Spec.Agile.HKDF.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val expand_loop:
a:fixed_len_alg
-> prk:bytes
-> info:bytes
-> n:nat
-> i:nat{i < n}
-> a_spec a i
-> Pure (a_spec a (i + 1) & Seq.lseq uint8 (hash_length a))
(requires
hash_length a <= Seq.length prk /\
HMAC.keysized a (Seq.length prk) /\
(hash_length a + Seq.length info + 1 + block_length a) `less_than_max_input_length` a /\
n <= 255)
(ensures fun _ -> True) | [] | Spec.Agile.HKDF.expand_loop | {
"file_name": "specs/Spec.Agile.HKDF.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Spec.Hash.Definitions.fixed_len_alg ->
prk: Spec.Hash.Definitions.bytes ->
info: Spec.Hash.Definitions.bytes ->
n: FStar.Integers.nat ->
i: FStar.Integers.nat{i < n} ->
tag: Spec.Agile.HKDF.a_spec a i
-> Prims.Pure
(Spec.Agile.HKDF.a_spec a (i + 1) *
Lib.Sequence.lseq Lib.IntTypes.uint8 (Spec.Hash.Definitions.hash_length a)) | {
"end_col": 6,
"end_line": 57,
"start_col": 36,
"start_line": 55
} |
Prims.Pure | val expand:
a: fixed_len_alg ->
prk: bytes ->
info: bytes ->
len: nat ->
Pure (lbytes len)
(requires
hash_length a <= Seq.length prk /\
HMAC.keysized a (Seq.length prk) /\
expand_info_length_pred a (Seq.length info) /\
expand_output_length_pred a len)
(ensures fun _ -> True) | [
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": false,
"full_module": "FStar.Seq",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Integers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Agile",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let expand a prk info len =
let open Spec.Agile.HMAC in
let tlen = hash_length a in
let n = len / tlen in
let tag, output =
Seq.generate_blocks tlen n n (a_spec a) (expand_loop a prk info n) FStar.Seq.empty
in
if n * tlen < len then
let t = hmac a prk (tag @| info @| Seq.create 1 (u8 (n + 1))) in
output @| Seq.sub #_ #tlen t 0 (len - (n * tlen))
else
output | val expand:
a: fixed_len_alg ->
prk: bytes ->
info: bytes ->
len: nat ->
Pure (lbytes len)
(requires
hash_length a <= Seq.length prk /\
HMAC.keysized a (Seq.length prk) /\
expand_info_length_pred a (Seq.length info) /\
expand_output_length_pred a len)
(ensures fun _ -> True)
let expand a prk info len = | false | null | false | let open Spec.Agile.HMAC in
let tlen = hash_length a in
let n = len / tlen in
let tag, output =
Seq.generate_blocks tlen n n (a_spec a) (expand_loop a prk info n) FStar.Seq.empty
in
if n * tlen < len
then
let t = hmac a prk (tag @| info @| Seq.create 1 (u8 (n + 1))) in
output @| Seq.sub #_ #tlen t 0 (len - (n * tlen))
else output | {
"checked_file": "Spec.Agile.HKDF.fst.checked",
"dependencies": [
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.HMAC.fsti.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Integers.fst.checked"
],
"interface_file": true,
"source_file": "Spec.Agile.HKDF.fst"
} | [] | [
"Spec.Hash.Definitions.fixed_len_alg",
"Spec.Hash.Definitions.bytes",
"FStar.Integers.nat",
"Spec.Agile.HKDF.a_spec",
"Lib.Sequence.seq",
"Lib.IntTypes.uint8",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.length",
"FStar.Mul.op_Star",
"FStar.Integers.op_Less",
"FStar.Integers.Signed",
"FStar.Integers.Winfinite",
"FStar.Integers.op_Star",
"FStar.Seq.Base.op_At_Bar",
"Lib.Sequence.sub",
"FStar.Integers.op_Subtraction",
"Spec.Agile.HMAC.lbytes",
"Spec.Hash.Definitions.hash_length",
"Spec.Agile.HMAC.hmac",
"Lib.Sequence.create",
"Lib.IntTypes.u8",
"FStar.Integers.op_Plus",
"Prims.bool",
"Spec.Agile.HKDF.lbytes",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Prims.op_Multiply",
"Lib.Sequence.generate_blocks",
"Spec.Agile.HKDF.expand_loop",
"FStar.Seq.Base.empty",
"FStar.Integers.int_t",
"FStar.Integers.op_Slash",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"Prims.op_GreaterThan"
] | [] | module Spec.Agile.HKDF
open FStar.Integers
open Spec.Hash.Definitions
/// FUNCTIONAL SPECIFICATION:
///
/// * extraction is just HMAC using the salt as key and the input
/// keying materials as text.
///
/// * expansion does its own formatting of input key materials.
open FStar.Seq
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
let extract = Spec.Agile.HMAC.hmac
module Seq = Lib.Sequence
open Lib.IntTypes
/// HKDF-Expand(PRK, info, L)
///
/// N = ceil(L/HashLen)
/// T = T(1) | T(2) | T(3) | ... | T(N)
/// OKM = first L octets of T
///
/// where:
/// T(0) = empty string (zero length)
/// T(1) = HMAC-Hash(PRK, T(0) | info | 0x01)
/// T(2) = HMAC-Hash(PRK, T(1) | info | 0x02)
/// T(3) = HMAC-Hash(PRK, T(2) | info | 0x03)
///
/// See https://tools.ietf.org/html/rfc5869#section-2.3
/// The type of T(i) is [a_spec a i]
let a_spec (a:fixed_len_alg) (i:nat) =
Seq.lseq uint8 (if i = 0 then 0 else hash_length a)
/// The main loop that computes T(i)
val expand_loop:
a:fixed_len_alg
-> prk:bytes
-> info:bytes
-> n:nat
-> i:nat{i < n}
-> a_spec a i
-> Pure (a_spec a (i + 1) & Seq.lseq uint8 (hash_length a))
(requires
hash_length a <= Seq.length prk /\
HMAC.keysized a (Seq.length prk) /\
(hash_length a + Seq.length info + 1 + block_length a) `less_than_max_input_length` a /\
n <= 255)
(ensures fun _ -> True)
let expand_loop a prk info n i tag =
let t = Spec.Agile.HMAC.hmac a prk (tag @| info @| Seq.create 1 (u8 (i + 1))) in
t, t
/// Expands first computes T(0) | T(1) | ... | T(floor(L/HashLen)) in a loop and then
/// if needed computes T(N) and appends as many bytes as required to complete OKM | false | false | Spec.Agile.HKDF.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val expand:
a: fixed_len_alg ->
prk: bytes ->
info: bytes ->
len: nat ->
Pure (lbytes len)
(requires
hash_length a <= Seq.length prk /\
HMAC.keysized a (Seq.length prk) /\
expand_info_length_pred a (Seq.length info) /\
expand_output_length_pred a len)
(ensures fun _ -> True) | [] | Spec.Agile.HKDF.expand | {
"file_name": "specs/Spec.Agile.HKDF.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Spec.Hash.Definitions.fixed_len_alg ->
prk: Spec.Hash.Definitions.bytes ->
info: Spec.Hash.Definitions.bytes ->
len: FStar.Integers.nat
-> Prims.Pure (Spec.Agile.HKDF.lbytes len) | {
"end_col": 10,
"end_line": 72,
"start_col": 2,
"start_line": 62
} |
Prims.Tot | val bn_sub_eq_len_u32 (aLen: size_t) : bn_sub_eq_len_st U32 aLen | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_eq_len_u32 (aLen:size_t) : bn_sub_eq_len_st U32 aLen = bn_sub_eq_len aLen | val bn_sub_eq_len_u32 (aLen: size_t) : bn_sub_eq_len_st U32 aLen
let bn_sub_eq_len_u32 (aLen: size_t) : bn_sub_eq_len_st U32 aLen = | false | null | false | bn_sub_eq_len aLen | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [
"total"
] | [
"Lib.IntTypes.size_t",
"Hacl.Bignum.Addition.bn_sub_eq_len",
"Lib.IntTypes.U32",
"Hacl.Bignum.Addition.bn_sub_eq_len_st"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_eq_len_u32 (aLen: size_t) : bn_sub_eq_len_st U32 aLen | [] | Hacl.Bignum.Addition.bn_sub_eq_len_u32 | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | aLen: Lib.IntTypes.size_t -> Hacl.Bignum.Addition.bn_sub_eq_len_st Lib.IntTypes.U32 aLen | {
"end_col": 84,
"end_line": 104,
"start_col": 66,
"start_line": 104
} |
Prims.Tot | val bn_sub_eq_len_u64 (aLen: size_t) : bn_sub_eq_len_st U64 aLen | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_eq_len_u64 (aLen:size_t) : bn_sub_eq_len_st U64 aLen = bn_sub_eq_len aLen | val bn_sub_eq_len_u64 (aLen: size_t) : bn_sub_eq_len_st U64 aLen
let bn_sub_eq_len_u64 (aLen: size_t) : bn_sub_eq_len_st U64 aLen = | false | null | false | bn_sub_eq_len aLen | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [
"total"
] | [
"Lib.IntTypes.size_t",
"Hacl.Bignum.Addition.bn_sub_eq_len",
"Lib.IntTypes.U64",
"Hacl.Bignum.Addition.bn_sub_eq_len_st"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_eq_len_u64 (aLen: size_t) : bn_sub_eq_len_st U64 aLen | [] | Hacl.Bignum.Addition.bn_sub_eq_len_u64 | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | aLen: Lib.IntTypes.size_t -> Hacl.Bignum.Addition.bn_sub_eq_len_st Lib.IntTypes.U64 aLen | {
"end_col": 84,
"end_line": 105,
"start_col": 66,
"start_line": 105
} |
Prims.Tot | val bn_add_eq_len_u64 (aLen: size_t) : bn_add_eq_len_st U64 aLen | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_eq_len_u64 (aLen:size_t) : bn_add_eq_len_st U64 aLen = bn_add_eq_len aLen | val bn_add_eq_len_u64 (aLen: size_t) : bn_add_eq_len_st U64 aLen
let bn_add_eq_len_u64 (aLen: size_t) : bn_add_eq_len_st U64 aLen = | false | null | false | bn_add_eq_len aLen | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [
"total"
] | [
"Lib.IntTypes.size_t",
"Hacl.Bignum.Addition.bn_add_eq_len",
"Lib.IntTypes.U64",
"Hacl.Bignum.Addition.bn_add_eq_len_st"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_sub_eq_len_u32 (aLen:size_t) : bn_sub_eq_len_st U32 aLen = bn_sub_eq_len aLen
let bn_sub_eq_len_u64 (aLen:size_t) : bn_sub_eq_len_st U64 aLen = bn_sub_eq_len aLen
inline_for_extraction noextract
let bn_sub_eq_len_u (#t:limb_t) (aLen:size_t) : bn_sub_eq_len_st t aLen =
match t with
| U32 -> bn_sub_eq_len_u32 aLen
| U64 -> bn_sub_eq_len_u64 aLen
inline_for_extraction noextract
val bn_sub:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r))
let bn_sub #t aLen a bLen b res =
let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let h1 = ST.get () in
let c0 = bn_sub_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen then begin
[@inline_let] let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1 end
else c0
inline_for_extraction noextract
val bn_sub1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r))
let bn_sub1 #t aLen a b1 res =
let c0 = subborrow_st (uint #t 0) a.(0ul) b1 (sub res 0ul 1ul) in
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 1) (LSeq.create 1 (LSeq.index (as_seq h0 res) 0));
if 1ul <. aLen then begin
[@inline_let] let rLen = aLen -! 1ul in
let a1 = sub a 1ul rLen in
let res1 = sub res 1ul rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h = ST.get () in
LSeq.lemma_concat2 1 (LSeq.sub (as_seq h0 res) 0 1) (v rLen) (as_seq h res1) (as_seq h res);
c1 end
else c0
inline_for_extraction noextract
val bn_add_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_add_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_add_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_add_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_add_eq_len: #t:limb_t -> aLen:size_t -> bn_add_eq_len_st t aLen
let bn_add_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_eq_len_u64 (aLen: size_t) : bn_add_eq_len_st U64 aLen | [] | Hacl.Bignum.Addition.bn_add_eq_len_u64 | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | aLen: Lib.IntTypes.size_t -> Hacl.Bignum.Addition.bn_add_eq_len_st Lib.IntTypes.U64 aLen | {
"end_col": 84,
"end_line": 262,
"start_col": 66,
"start_line": 262
} |
Prims.Tot | val bn_add_eq_len_u32 (aLen: size_t) : bn_add_eq_len_st U32 aLen | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_eq_len_u32 (aLen:size_t) : bn_add_eq_len_st U32 aLen = bn_add_eq_len aLen | val bn_add_eq_len_u32 (aLen: size_t) : bn_add_eq_len_st U32 aLen
let bn_add_eq_len_u32 (aLen: size_t) : bn_add_eq_len_st U32 aLen = | false | null | false | bn_add_eq_len aLen | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [
"total"
] | [
"Lib.IntTypes.size_t",
"Hacl.Bignum.Addition.bn_add_eq_len",
"Lib.IntTypes.U32",
"Hacl.Bignum.Addition.bn_add_eq_len_st"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_sub_eq_len_u32 (aLen:size_t) : bn_sub_eq_len_st U32 aLen = bn_sub_eq_len aLen
let bn_sub_eq_len_u64 (aLen:size_t) : bn_sub_eq_len_st U64 aLen = bn_sub_eq_len aLen
inline_for_extraction noextract
let bn_sub_eq_len_u (#t:limb_t) (aLen:size_t) : bn_sub_eq_len_st t aLen =
match t with
| U32 -> bn_sub_eq_len_u32 aLen
| U64 -> bn_sub_eq_len_u64 aLen
inline_for_extraction noextract
val bn_sub:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r))
let bn_sub #t aLen a bLen b res =
let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let h1 = ST.get () in
let c0 = bn_sub_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen then begin
[@inline_let] let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1 end
else c0
inline_for_extraction noextract
val bn_sub1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r))
let bn_sub1 #t aLen a b1 res =
let c0 = subborrow_st (uint #t 0) a.(0ul) b1 (sub res 0ul 1ul) in
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 1) (LSeq.create 1 (LSeq.index (as_seq h0 res) 0));
if 1ul <. aLen then begin
[@inline_let] let rLen = aLen -! 1ul in
let a1 = sub a 1ul rLen in
let res1 = sub res 1ul rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h = ST.get () in
LSeq.lemma_concat2 1 (LSeq.sub (as_seq h0 res) 0 1) (v rLen) (as_seq h res1) (as_seq h res);
c1 end
else c0
inline_for_extraction noextract
val bn_add_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_add_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_add_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_add_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_add_eq_len: #t:limb_t -> aLen:size_t -> bn_add_eq_len_st t aLen
let bn_add_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_eq_len_u32 (aLen: size_t) : bn_add_eq_len_st U32 aLen | [] | Hacl.Bignum.Addition.bn_add_eq_len_u32 | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | aLen: Lib.IntTypes.size_t -> Hacl.Bignum.Addition.bn_add_eq_len_st Lib.IntTypes.U32 aLen | {
"end_col": 84,
"end_line": 261,
"start_col": 66,
"start_line": 261
} |
Prims.Tot | val bn_sub_eq_len_u (#t: limb_t) (aLen: size_t) : bn_sub_eq_len_st t aLen | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_eq_len_u (#t:limb_t) (aLen:size_t) : bn_sub_eq_len_st t aLen =
match t with
| U32 -> bn_sub_eq_len_u32 aLen
| U64 -> bn_sub_eq_len_u64 aLen | val bn_sub_eq_len_u (#t: limb_t) (aLen: size_t) : bn_sub_eq_len_st t aLen
let bn_sub_eq_len_u (#t: limb_t) (aLen: size_t) : bn_sub_eq_len_st t aLen = | false | null | false | match t with
| U32 -> bn_sub_eq_len_u32 aLen
| U64 -> bn_sub_eq_len_u64 aLen | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Addition.bn_sub_eq_len_u32",
"Hacl.Bignum.Addition.bn_sub_eq_len_u64",
"Hacl.Bignum.Addition.bn_sub_eq_len_st"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_sub_eq_len_u32 (aLen:size_t) : bn_sub_eq_len_st U32 aLen = bn_sub_eq_len aLen
let bn_sub_eq_len_u64 (aLen:size_t) : bn_sub_eq_len_st U64 aLen = bn_sub_eq_len aLen
inline_for_extraction noextract | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_eq_len_u (#t: limb_t) (aLen: size_t) : bn_sub_eq_len_st t aLen | [] | Hacl.Bignum.Addition.bn_sub_eq_len_u | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | aLen: Lib.IntTypes.size_t -> Hacl.Bignum.Addition.bn_sub_eq_len_st t aLen | {
"end_col": 33,
"end_line": 111,
"start_col": 2,
"start_line": 109
} |
Prims.Tot | val bn_add_eq_len_u (#t: limb_t) (aLen: size_t) : bn_add_eq_len_st t aLen | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_eq_len_u (#t:limb_t) (aLen:size_t) : bn_add_eq_len_st t aLen =
match t with
| U32 -> bn_add_eq_len_u32 aLen
| U64 -> bn_add_eq_len_u64 aLen | val bn_add_eq_len_u (#t: limb_t) (aLen: size_t) : bn_add_eq_len_st t aLen
let bn_add_eq_len_u (#t: limb_t) (aLen: size_t) : bn_add_eq_len_st t aLen = | false | null | false | match t with
| U32 -> bn_add_eq_len_u32 aLen
| U64 -> bn_add_eq_len_u64 aLen | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Addition.bn_add_eq_len_u32",
"Hacl.Bignum.Addition.bn_add_eq_len_u64",
"Hacl.Bignum.Addition.bn_add_eq_len_st"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_sub_eq_len_u32 (aLen:size_t) : bn_sub_eq_len_st U32 aLen = bn_sub_eq_len aLen
let bn_sub_eq_len_u64 (aLen:size_t) : bn_sub_eq_len_st U64 aLen = bn_sub_eq_len aLen
inline_for_extraction noextract
let bn_sub_eq_len_u (#t:limb_t) (aLen:size_t) : bn_sub_eq_len_st t aLen =
match t with
| U32 -> bn_sub_eq_len_u32 aLen
| U64 -> bn_sub_eq_len_u64 aLen
inline_for_extraction noextract
val bn_sub:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r))
let bn_sub #t aLen a bLen b res =
let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let h1 = ST.get () in
let c0 = bn_sub_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen then begin
[@inline_let] let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1 end
else c0
inline_for_extraction noextract
val bn_sub1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r))
let bn_sub1 #t aLen a b1 res =
let c0 = subborrow_st (uint #t 0) a.(0ul) b1 (sub res 0ul 1ul) in
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 1) (LSeq.create 1 (LSeq.index (as_seq h0 res) 0));
if 1ul <. aLen then begin
[@inline_let] let rLen = aLen -! 1ul in
let a1 = sub a 1ul rLen in
let res1 = sub res 1ul rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h = ST.get () in
LSeq.lemma_concat2 1 (LSeq.sub (as_seq h0 res) 0 1) (v rLen) (as_seq h res1) (as_seq h res);
c1 end
else c0
inline_for_extraction noextract
val bn_add_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_add_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_add_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_add_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_add_eq_len: #t:limb_t -> aLen:size_t -> bn_add_eq_len_st t aLen
let bn_add_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_add_eq_len_u32 (aLen:size_t) : bn_add_eq_len_st U32 aLen = bn_add_eq_len aLen
let bn_add_eq_len_u64 (aLen:size_t) : bn_add_eq_len_st U64 aLen = bn_add_eq_len aLen
inline_for_extraction noextract | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_eq_len_u (#t: limb_t) (aLen: size_t) : bn_add_eq_len_st t aLen | [] | Hacl.Bignum.Addition.bn_add_eq_len_u | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | aLen: Lib.IntTypes.size_t -> Hacl.Bignum.Addition.bn_add_eq_len_st t aLen | {
"end_col": 33,
"end_line": 268,
"start_col": 2,
"start_line": 266
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r)) | let bn_sub_eq_len_st (t: limb_t) (aLen: size_t) = | false | null | false | a: lbignum t aLen -> b: lbignum t aLen -> res: lbignum t aLen
-> Stack (carry t)
(requires
fun h ->
live h a /\ live h b /\ live h res /\ eq_or_disjoint a b /\ eq_or_disjoint a res /\
eq_or_disjoint b res)
(ensures
fun h0 c_out h1 ->
modifies (loc res) h0 h1 /\
(let c, r =
SL.generate_elems (v aLen)
(v aLen)
(S.bn_sub_f (as_seq h0 a) (as_seq h0 b))
(uint #t 0)
in
c_out == c /\ as_seq h1 res == r)) | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.eq_or_disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Sequence.seq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.eq2",
"Prims.nat",
"Lib.Sequence.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.l_or",
"FStar.Seq.Base.length",
"Lib.Buffer.as_seq",
"Prims.logical",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Lib.generate_elems",
"Hacl.Spec.Bignum.Addition.bn_sub_f",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract | false | true | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_eq_len_st : t: Hacl.Bignum.Definitions.limb_t -> aLen: Lib.IntTypes.size_t -> Type0 | [] | Hacl.Bignum.Addition.bn_sub_eq_len_st | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> aLen: Lib.IntTypes.size_t -> Type0 | {
"end_col": 38,
"end_line": 72,
"start_col": 4,
"start_line": 63
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_add_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r)) | let bn_add_eq_len_st (t: limb_t) (aLen: size_t) = | false | null | false | a: lbignum t aLen -> b: lbignum t aLen -> res: lbignum t aLen
-> Stack (carry t)
(requires
fun h ->
live h a /\ live h b /\ live h res /\ eq_or_disjoint a b /\ eq_or_disjoint a res /\
eq_or_disjoint b res)
(ensures
fun h0 c_out h1 ->
modifies (loc res) h0 h1 /\
(let c, r =
SL.generate_elems (v aLen)
(v aLen)
(S.bn_add_f (as_seq h0 a) (as_seq h0 b))
(uint #t 0)
in
c_out == c /\ as_seq h1 res == r)) | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.eq_or_disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Lib.Sequence.seq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.eq2",
"Prims.nat",
"Lib.Sequence.length",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.l_or",
"FStar.Seq.Base.length",
"Lib.Buffer.as_seq",
"Prims.logical",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Lib.generate_elems",
"Hacl.Spec.Bignum.Addition.bn_add_f",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_sub_eq_len_u32 (aLen:size_t) : bn_sub_eq_len_st U32 aLen = bn_sub_eq_len aLen
let bn_sub_eq_len_u64 (aLen:size_t) : bn_sub_eq_len_st U64 aLen = bn_sub_eq_len aLen
inline_for_extraction noextract
let bn_sub_eq_len_u (#t:limb_t) (aLen:size_t) : bn_sub_eq_len_st t aLen =
match t with
| U32 -> bn_sub_eq_len_u32 aLen
| U64 -> bn_sub_eq_len_u64 aLen
inline_for_extraction noextract
val bn_sub:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r))
let bn_sub #t aLen a bLen b res =
let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let h1 = ST.get () in
let c0 = bn_sub_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen then begin
[@inline_let] let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1 end
else c0
inline_for_extraction noextract
val bn_sub1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r))
let bn_sub1 #t aLen a b1 res =
let c0 = subborrow_st (uint #t 0) a.(0ul) b1 (sub res 0ul 1ul) in
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 1) (LSeq.create 1 (LSeq.index (as_seq h0 res) 0));
if 1ul <. aLen then begin
[@inline_let] let rLen = aLen -! 1ul in
let a1 = sub a 1ul rLen in
let res1 = sub res 1ul rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h = ST.get () in
LSeq.lemma_concat2 1 (LSeq.sub (as_seq h0 res) 0 1) (v rLen) (as_seq h res1) (as_seq h res);
c1 end
else c0
inline_for_extraction noextract
val bn_add_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_add_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract | false | true | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_eq_len_st : t: Hacl.Bignum.Definitions.limb_t -> aLen: Lib.IntTypes.size_t -> Type0 | [] | Hacl.Bignum.Addition.bn_add_eq_len_st | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> aLen: Lib.IntTypes.size_t -> Type0 | {
"end_col": 38,
"end_line": 228,
"start_col": 4,
"start_line": 219
} |
|
FStar.HyperStack.ST.Stack | val bn_sub:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r)) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub #t aLen a bLen b res =
let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let h1 = ST.get () in
let c0 = bn_sub_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen then begin
[@inline_let] let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1 end
else c0 | val bn_sub:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r))
let bn_sub #t aLen a bLen b res = | true | null | false | let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let h1 = ST.get () in
let c0 = bn_sub_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen
then
[@@ inline_let ]let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1
else c0 | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.op_Less_Dot",
"Prims.unit",
"Lib.Sequence.lemma_concat2",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Spec.Bignum.Base.carry",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Bignum.Addition.bn_sub_carry",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.sub",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Subtraction_Bang",
"Prims.bool",
"Hacl.Bignum.Addition.bn_sub_eq_len",
"FStar.UInt32.__uint_to_t"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_sub_eq_len_u32 (aLen:size_t) : bn_sub_eq_len_st U32 aLen = bn_sub_eq_len aLen
let bn_sub_eq_len_u64 (aLen:size_t) : bn_sub_eq_len_st U64 aLen = bn_sub_eq_len aLen
inline_for_extraction noextract
let bn_sub_eq_len_u (#t:limb_t) (aLen:size_t) : bn_sub_eq_len_st t aLen =
match t with
| U32 -> bn_sub_eq_len_u32 aLen
| U64 -> bn_sub_eq_len_u64 aLen
inline_for_extraction noextract
val bn_sub:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r)) | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r)) | [] | Hacl.Bignum.Addition.bn_sub | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
aLen: Lib.IntTypes.size_t ->
a: Hacl.Bignum.Definitions.lbignum t aLen ->
bLen: Lib.IntTypes.size_t{Lib.IntTypes.v bLen <= Lib.IntTypes.v aLen} ->
b: Hacl.Bignum.Definitions.lbignum t bLen ->
res: Hacl.Bignum.Definitions.lbignum t aLen
-> FStar.HyperStack.ST.Stack (Hacl.Spec.Bignum.Base.carry t) | {
"end_col": 9,
"end_line": 145,
"start_col": 33,
"start_line": 130
} |
FStar.HyperStack.ST.Stack | val bn_add:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r)) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add #t aLen a bLen b res =
let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let c0 = bn_add_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen then begin
[@inline_let] let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_add_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1 end
else c0 | val bn_add:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r))
let bn_add #t aLen a bLen b res = | true | null | false | let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let c0 = bn_add_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen
then
[@@ inline_let ]let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_add_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1
else c0 | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.op_Less_Dot",
"Prims.unit",
"Lib.Sequence.lemma_concat2",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Spec.Bignum.Base.carry",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Bignum.Addition.bn_add_carry",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.sub",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Subtraction_Bang",
"Prims.bool",
"Hacl.Bignum.Addition.bn_add_eq_len",
"FStar.UInt32.__uint_to_t"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_sub_eq_len_u32 (aLen:size_t) : bn_sub_eq_len_st U32 aLen = bn_sub_eq_len aLen
let bn_sub_eq_len_u64 (aLen:size_t) : bn_sub_eq_len_st U64 aLen = bn_sub_eq_len aLen
inline_for_extraction noextract
let bn_sub_eq_len_u (#t:limb_t) (aLen:size_t) : bn_sub_eq_len_st t aLen =
match t with
| U32 -> bn_sub_eq_len_u32 aLen
| U64 -> bn_sub_eq_len_u64 aLen
inline_for_extraction noextract
val bn_sub:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r))
let bn_sub #t aLen a bLen b res =
let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let h1 = ST.get () in
let c0 = bn_sub_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen then begin
[@inline_let] let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1 end
else c0
inline_for_extraction noextract
val bn_sub1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r))
let bn_sub1 #t aLen a b1 res =
let c0 = subborrow_st (uint #t 0) a.(0ul) b1 (sub res 0ul 1ul) in
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 1) (LSeq.create 1 (LSeq.index (as_seq h0 res) 0));
if 1ul <. aLen then begin
[@inline_let] let rLen = aLen -! 1ul in
let a1 = sub a 1ul rLen in
let res1 = sub res 1ul rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h = ST.get () in
LSeq.lemma_concat2 1 (LSeq.sub (as_seq h0 res) 0 1) (v rLen) (as_seq h res1) (as_seq h res);
c1 end
else c0
inline_for_extraction noextract
val bn_add_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_add_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_add_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_add_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_add_eq_len: #t:limb_t -> aLen:size_t -> bn_add_eq_len_st t aLen
let bn_add_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_add_eq_len_u32 (aLen:size_t) : bn_add_eq_len_st U32 aLen = bn_add_eq_len aLen
let bn_add_eq_len_u64 (aLen:size_t) : bn_add_eq_len_st U64 aLen = bn_add_eq_len aLen
inline_for_extraction noextract
let bn_add_eq_len_u (#t:limb_t) (aLen:size_t) : bn_add_eq_len_st t aLen =
match t with
| U32 -> bn_add_eq_len_u32 aLen
| U64 -> bn_add_eq_len_u64 aLen
inline_for_extraction noextract
val bn_add:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r)) | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r)) | [] | Hacl.Bignum.Addition.bn_add | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
aLen: Lib.IntTypes.size_t ->
a: Hacl.Bignum.Definitions.lbignum t aLen ->
bLen: Lib.IntTypes.size_t{Lib.IntTypes.v bLen <= Lib.IntTypes.v aLen} ->
b: Hacl.Bignum.Definitions.lbignum t bLen ->
res: Hacl.Bignum.Definitions.lbignum t aLen
-> FStar.HyperStack.ST.Stack (Hacl.Spec.Bignum.Base.carry t) | {
"end_col": 9,
"end_line": 301,
"start_col": 33,
"start_line": 287
} |
FStar.HyperStack.ST.Stack | val bn_add1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r)) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add1 #t aLen a b1 res =
let c0 = addcarry_st (uint #t 0) a.(0ul) b1 (sub res 0ul 1ul) in
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 1) (LSeq.create 1 (LSeq.index (as_seq h0 res) 0));
if 1ul <. aLen then begin
[@inline_let] let rLen = aLen -! 1ul in
let a1 = sub a 1ul rLen in
let res1 = sub res 1ul rLen in
let c1 = bn_add_carry rLen a1 c0 res1 in
let h = ST.get () in
LSeq.lemma_concat2 1 (LSeq.sub (as_seq h0 res) 0 1) (v rLen) (as_seq h res1) (as_seq h res);
c1 end
else c0 | val bn_add1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r))
let bn_add1 #t aLen a b1 res = | true | null | false | let c0 = addcarry_st (uint #t 0) a.(0ul) b1 (sub res 0ul 1ul) in
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 1) (LSeq.create 1 (LSeq.index (as_seq h0 res) 0));
if 1ul <. aLen
then
[@@ inline_let ]let rLen = aLen -! 1ul in
let a1 = sub a 1ul rLen in
let res1 = sub res 1ul rLen in
let c1 = bn_add_carry rLen a1 c0 res1 in
let h = ST.get () in
LSeq.lemma_concat2 1 (LSeq.sub (as_seq h0 res) 0 1) (v rLen) (as_seq h res1) (as_seq h res);
c1
else c0 | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.Definitions.limb",
"Lib.IntTypes.op_Less_Dot",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Lib.Sequence.lemma_concat2",
"Lib.Sequence.sub",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Spec.Bignum.Base.carry",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Bignum.Addition.bn_add_carry",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.sub",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Subtraction_Bang",
"Prims.bool",
"Lib.Sequence.eq_intro",
"Lib.Sequence.create",
"Lib.Sequence.index",
"Hacl.Bignum.Base.addcarry_st",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.op_Array_Access"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_sub_eq_len_u32 (aLen:size_t) : bn_sub_eq_len_st U32 aLen = bn_sub_eq_len aLen
let bn_sub_eq_len_u64 (aLen:size_t) : bn_sub_eq_len_st U64 aLen = bn_sub_eq_len aLen
inline_for_extraction noextract
let bn_sub_eq_len_u (#t:limb_t) (aLen:size_t) : bn_sub_eq_len_st t aLen =
match t with
| U32 -> bn_sub_eq_len_u32 aLen
| U64 -> bn_sub_eq_len_u64 aLen
inline_for_extraction noextract
val bn_sub:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r))
let bn_sub #t aLen a bLen b res =
let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let h1 = ST.get () in
let c0 = bn_sub_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen then begin
[@inline_let] let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1 end
else c0
inline_for_extraction noextract
val bn_sub1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r))
let bn_sub1 #t aLen a b1 res =
let c0 = subborrow_st (uint #t 0) a.(0ul) b1 (sub res 0ul 1ul) in
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 1) (LSeq.create 1 (LSeq.index (as_seq h0 res) 0));
if 1ul <. aLen then begin
[@inline_let] let rLen = aLen -! 1ul in
let a1 = sub a 1ul rLen in
let res1 = sub res 1ul rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h = ST.get () in
LSeq.lemma_concat2 1 (LSeq.sub (as_seq h0 res) 0 1) (v rLen) (as_seq h res1) (as_seq h res);
c1 end
else c0
inline_for_extraction noextract
val bn_add_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_add_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_add_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_add_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_add_eq_len: #t:limb_t -> aLen:size_t -> bn_add_eq_len_st t aLen
let bn_add_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_add_eq_len_u32 (aLen:size_t) : bn_add_eq_len_st U32 aLen = bn_add_eq_len aLen
let bn_add_eq_len_u64 (aLen:size_t) : bn_add_eq_len_st U64 aLen = bn_add_eq_len aLen
inline_for_extraction noextract
let bn_add_eq_len_u (#t:limb_t) (aLen:size_t) : bn_add_eq_len_st t aLen =
match t with
| U32 -> bn_add_eq_len_u32 aLen
| U64 -> bn_add_eq_len_u64 aLen
inline_for_extraction noextract
val bn_add:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r))
let bn_add #t aLen a bLen b res =
let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let c0 = bn_add_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen then begin
[@inline_let] let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_add_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1 end
else c0
inline_for_extraction noextract
val bn_add1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r)) | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r)) | [] | Hacl.Bignum.Addition.bn_add1 | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
aLen: Lib.IntTypes.size_t{0 < Lib.IntTypes.v aLen} ->
a: Hacl.Bignum.Definitions.lbignum t aLen ->
b1: Hacl.Bignum.Definitions.limb t ->
res: Hacl.Bignum.Definitions.lbignum t aLen
-> FStar.HyperStack.ST.Stack (Hacl.Spec.Bignum.Base.carry t) | {
"end_col": 9,
"end_line": 331,
"start_col": 30,
"start_line": 318
} |
FStar.HyperStack.ST.Stack | val bn_sub1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r)) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub1 #t aLen a b1 res =
let c0 = subborrow_st (uint #t 0) a.(0ul) b1 (sub res 0ul 1ul) in
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 1) (LSeq.create 1 (LSeq.index (as_seq h0 res) 0));
if 1ul <. aLen then begin
[@inline_let] let rLen = aLen -! 1ul in
let a1 = sub a 1ul rLen in
let res1 = sub res 1ul rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h = ST.get () in
LSeq.lemma_concat2 1 (LSeq.sub (as_seq h0 res) 0 1) (v rLen) (as_seq h res1) (as_seq h res);
c1 end
else c0 | val bn_sub1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r))
let bn_sub1 #t aLen a b1 res = | true | null | false | let c0 = subborrow_st (uint #t 0) a.(0ul) b1 (sub res 0ul 1ul) in
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 1) (LSeq.create 1 (LSeq.index (as_seq h0 res) 0));
if 1ul <. aLen
then
[@@ inline_let ]let rLen = aLen -! 1ul in
let a1 = sub a 1ul rLen in
let res1 = sub res 1ul rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h = ST.get () in
LSeq.lemma_concat2 1 (LSeq.sub (as_seq h0 res) 0 1) (v rLen) (as_seq h res1) (as_seq h res);
c1
else c0 | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.Definitions.limb",
"Lib.IntTypes.op_Less_Dot",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Lib.Sequence.lemma_concat2",
"Lib.Sequence.sub",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Spec.Bignum.Base.carry",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Bignum.Addition.bn_sub_carry",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.sub",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Subtraction_Bang",
"Prims.bool",
"Lib.Sequence.eq_intro",
"Lib.Sequence.create",
"Lib.Sequence.index",
"Hacl.Bignum.Base.subborrow_st",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.op_Array_Access"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_sub_eq_len_u32 (aLen:size_t) : bn_sub_eq_len_st U32 aLen = bn_sub_eq_len aLen
let bn_sub_eq_len_u64 (aLen:size_t) : bn_sub_eq_len_st U64 aLen = bn_sub_eq_len aLen
inline_for_extraction noextract
let bn_sub_eq_len_u (#t:limb_t) (aLen:size_t) : bn_sub_eq_len_st t aLen =
match t with
| U32 -> bn_sub_eq_len_u32 aLen
| U64 -> bn_sub_eq_len_u64 aLen
inline_for_extraction noextract
val bn_sub:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r))
let bn_sub #t aLen a bLen b res =
let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let h1 = ST.get () in
let c0 = bn_sub_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen then begin
[@inline_let] let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1 end
else c0
inline_for_extraction noextract
val bn_sub1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r)) | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r)) | [] | Hacl.Bignum.Addition.bn_sub1 | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
aLen: Lib.IntTypes.size_t{0 < Lib.IntTypes.v aLen} ->
a: Hacl.Bignum.Definitions.lbignum t aLen ->
b1: Hacl.Bignum.Definitions.limb t ->
res: Hacl.Bignum.Definitions.lbignum t aLen
-> FStar.HyperStack.ST.Stack (Hacl.Spec.Bignum.Base.carry t) | {
"end_col": 9,
"end_line": 175,
"start_col": 30,
"start_line": 162
} |
Prims.Tot | val bn_add_eq_len: #t:limb_t -> aLen:size_t -> bn_add_eq_len_st t aLen | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res | val bn_add_eq_len: #t:limb_t -> aLen:size_t -> bn_add_eq_len_st t aLen
let bn_add_eq_len #t aLen a b res = | false | null | false | push_frame ();
let c = create 1ul (uint #t 0) in
[@@ inline_let ]let refl h i = LSeq.index (as_seq h c) 0 in
[@@ inline_let ]let footprint (i: size_nat{i <= v aLen})
: GTot
(l: B.loc{B.loc_disjoint l (loc res) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})
=
loc c
in
[@@ inline_let ]let spec h = S.bn_add_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0
aLen
res
refl
footprint
spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1);
let res = c.(0ul) in
pop_frame ();
res | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Lib.fill_elems4",
"Hacl.Bignum.Definitions.limb",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Lib.lemma_eq_disjoint",
"Lib.Buffer.op_Array_Assignment",
"Hacl.Bignum.Base.addcarry_st",
"Lib.Buffer.lbuffer_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Addition.bn_add_f",
"Lib.Buffer.as_seq",
"LowStar.Monotonic.Buffer.loc",
"Prims.l_and",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Lib.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.address_liveness_insensitive_locs",
"Lib.IntTypes.size_nat",
"Prims.eq2",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Buffer.create",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_sub_eq_len_u32 (aLen:size_t) : bn_sub_eq_len_st U32 aLen = bn_sub_eq_len aLen
let bn_sub_eq_len_u64 (aLen:size_t) : bn_sub_eq_len_st U64 aLen = bn_sub_eq_len aLen
inline_for_extraction noextract
let bn_sub_eq_len_u (#t:limb_t) (aLen:size_t) : bn_sub_eq_len_st t aLen =
match t with
| U32 -> bn_sub_eq_len_u32 aLen
| U64 -> bn_sub_eq_len_u64 aLen
inline_for_extraction noextract
val bn_sub:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r))
let bn_sub #t aLen a bLen b res =
let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let h1 = ST.get () in
let c0 = bn_sub_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen then begin
[@inline_let] let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1 end
else c0
inline_for_extraction noextract
val bn_sub1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r))
let bn_sub1 #t aLen a b1 res =
let c0 = subborrow_st (uint #t 0) a.(0ul) b1 (sub res 0ul 1ul) in
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 1) (LSeq.create 1 (LSeq.index (as_seq h0 res) 0));
if 1ul <. aLen then begin
[@inline_let] let rLen = aLen -! 1ul in
let a1 = sub a 1ul rLen in
let res1 = sub res 1ul rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h = ST.get () in
LSeq.lemma_concat2 1 (LSeq.sub (as_seq h0 res) 0 1) (v rLen) (as_seq h res1) (as_seq h res);
c1 end
else c0
inline_for_extraction noextract
val bn_add_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_add_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_add_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_add_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_add_eq_len: #t:limb_t -> aLen:size_t -> bn_add_eq_len_st t aLen | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_eq_len: #t:limb_t -> aLen:size_t -> bn_add_eq_len_st t aLen | [] | Hacl.Bignum.Addition.bn_add_eq_len | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | aLen: Lib.IntTypes.size_t -> Hacl.Bignum.Addition.bn_add_eq_len_st t aLen | {
"end_col": 5,
"end_line": 258,
"start_col": 2,
"start_line": 234
} |
Prims.Tot | val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res | val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res = | false | null | false | push_frame ();
let c = create 1ul (uint #t 0) in
[@@ inline_let ]let refl h i = LSeq.index (as_seq h c) 0 in
[@@ inline_let ]let footprint (i: size_nat{i <= v aLen})
: GTot
(l: B.loc{B.loc_disjoint l (loc res) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})
=
loc c
in
[@@ inline_let ]let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0
aLen
res
refl
footprint
spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1);
let res = c.(0ul) in
pop_frame ();
res | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Lib.fill_elems4",
"Hacl.Bignum.Definitions.limb",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Lib.lemma_eq_disjoint",
"Lib.Buffer.op_Array_Assignment",
"Hacl.Bignum.Base.subborrow_st",
"Lib.Buffer.lbuffer_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Addition.bn_sub_f",
"Lib.Buffer.as_seq",
"LowStar.Monotonic.Buffer.loc",
"Prims.l_and",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Lib.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.address_liveness_insensitive_locs",
"Lib.IntTypes.size_nat",
"Prims.eq2",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Buffer.create",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen | [] | Hacl.Bignum.Addition.bn_sub_eq_len | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | aLen: Lib.IntTypes.size_t -> Hacl.Bignum.Addition.bn_sub_eq_len_st t aLen | {
"end_col": 5,
"end_line": 102,
"start_col": 2,
"start_line": 78
} |
FStar.HyperStack.ST.Stack | val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r)) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res | val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res = | true | null | false | push_frame ();
let c = create 1ul c_in in
[@@ inline_let ]let refl h i = LSeq.index (as_seq h c) 0 in
[@@ inline_let ]let footprint (i: size_nat{i <= v aLen})
: GTot
(l: B.loc{B.loc_disjoint l (loc res) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})
=
loc c
in
[@@ inline_let ]let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0
aLen
res
refl
footprint
spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1);
let res = c.(0ul) in
pop_frame ();
res | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Lib.fill_elems4",
"Hacl.Bignum.Definitions.limb",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Lib.lemma_eq_disjoint",
"Lib.Buffer.op_Array_Assignment",
"Hacl.Bignum.Base.subborrow_st",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Lib.Buffer.lbuffer_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Addition.bn_sub_carry_f",
"Lib.Buffer.as_seq",
"LowStar.Monotonic.Buffer.loc",
"Prims.l_and",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Lib.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.address_liveness_insensitive_locs",
"Lib.IntTypes.size_nat",
"Prims.eq2",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Buffer.create",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r)) | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r)) | [] | Hacl.Bignum.Addition.bn_sub_carry | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
aLen: Lib.IntTypes.size_t ->
a: Hacl.Bignum.Definitions.lbignum t aLen ->
c_in: Hacl.Spec.Bignum.Base.carry t ->
res: Hacl.Bignum.Definitions.lbignum t aLen
-> FStar.HyperStack.ST.Stack (Hacl.Spec.Bignum.Base.carry t) | {
"end_col": 5,
"end_line": 58,
"start_col": 2,
"start_line": 36
} |
FStar.HyperStack.ST.Stack | val bn_add_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r)) | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Lib",
"short_module": "SL"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Addition",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_add_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res | val bn_add_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_add_carry #t aLen a c_in res = | true | null | false | push_frame ();
let c = create 1ul c_in in
[@@ inline_let ]let refl h i = LSeq.index (as_seq h c) 0 in
[@@ inline_let ]let footprint (i: size_nat{i <= v aLen})
: GTot
(l: B.loc{B.loc_disjoint l (loc res) /\ B.address_liveness_insensitive_locs `B.loc_includes` l})
=
loc c
in
[@@ inline_let ]let spec h = S.bn_add_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0
aLen
res
refl
footprint
spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- addcarry_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1);
let res = c.(0ul) in
pop_frame ();
res | {
"checked_file": "Hacl.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Addition.fst"
} | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Lib.Buffer.op_Array_Access",
"Lib.Buffer.MUT",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Lib.fill_elems4",
"Hacl.Bignum.Definitions.limb",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Lib.lemma_eq_disjoint",
"Lib.Buffer.op_Array_Assignment",
"Hacl.Bignum.Base.addcarry_st",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Lib.Buffer.lbuffer_t",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Prims.op_Subtraction",
"Prims.pow2",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Addition.bn_add_carry_f",
"Lib.Buffer.as_seq",
"LowStar.Monotonic.Buffer.loc",
"Prims.l_and",
"LowStar.Monotonic.Buffer.loc_disjoint",
"Lib.Buffer.loc",
"LowStar.Monotonic.Buffer.loc_includes",
"LowStar.Monotonic.Buffer.address_liveness_insensitive_locs",
"Lib.IntTypes.size_nat",
"Prims.eq2",
"FStar.Seq.Base.index",
"Lib.Sequence.to_seq",
"Lib.Sequence.index",
"Lib.Buffer.create",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Bignum.Addition
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module B = LowStar.Buffer
module S = Hacl.Spec.Bignum.Addition
module LSeq = Lib.Sequence
module SL = Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
val bn_sub_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r))
let bn_sub_carry #t aLen a c_in res =
push_frame ();
let c = create 1ul c_in in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_carry_f (as_seq h a) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 (uint #t 0) res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
inline_for_extraction noextract
let bn_sub_eq_len_st (t:limb_t) (aLen:size_t) =
a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
eq_or_disjoint a b /\ eq_or_disjoint a res /\ eq_or_disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = SL.generate_elems (v aLen) (v aLen) (S.bn_sub_f (as_seq h0 a) (as_seq h0 b)) (uint #t 0) in
c_out == c /\ as_seq h1 res == r))
inline_for_extraction noextract
val bn_sub_eq_len: #t:limb_t -> aLen:size_t -> bn_sub_eq_len_st t aLen
let bn_sub_eq_len #t aLen a b res =
push_frame ();
let c = create 1ul (uint #t 0) in
[@inline_let]
let refl h i = LSeq.index (as_seq h c) 0 in
[@inline_let]
let footprint (i:size_nat{i <= v aLen}) : GTot (l:B.loc{B.loc_disjoint l (loc res) /\
B.address_liveness_insensitive_locs `B.loc_includes` l}) = loc c in
[@inline_let]
let spec h = S.bn_sub_f (as_seq h a) (as_seq h b) in
let h0 = ST.get () in
fill_elems4 h0 aLen res refl footprint spec
(fun i ->
let h1 = ST.get () in
let t1 = a.(i) in
let t2 = b.(i) in
let res_i = sub res i 1ul in
c.(0ul) <- subborrow_st c.(0ul) t1 t2 res_i;
lemma_eq_disjoint aLen aLen 1ul res a c i h0 h1;
lemma_eq_disjoint aLen aLen 1ul res b c i h0 h1
);
let res = c.(0ul) in
pop_frame ();
res
let bn_sub_eq_len_u32 (aLen:size_t) : bn_sub_eq_len_st U32 aLen = bn_sub_eq_len aLen
let bn_sub_eq_len_u64 (aLen:size_t) : bn_sub_eq_len_st U64 aLen = bn_sub_eq_len aLen
inline_for_extraction noextract
let bn_sub_eq_len_u (#t:limb_t) (aLen:size_t) : bn_sub_eq_len_st t aLen =
match t with
| U32 -> bn_sub_eq_len_u32 aLen
| U64 -> bn_sub_eq_len_u64 aLen
inline_for_extraction noextract
val bn_sub:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> bLen:size_t{v bLen <= v aLen}
-> b:lbignum t bLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint a b /\ eq_or_disjoint a res /\ disjoint b res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub (as_seq h0 a) (as_seq h0 b) in
c_out == c /\ as_seq h1 res == r))
let bn_sub #t aLen a bLen b res =
let h0 = ST.get () in
let a0 = sub a 0ul bLen in
let res0 = sub res 0ul bLen in
let h1 = ST.get () in
let c0 = bn_sub_eq_len bLen a0 b res0 in
let h1 = ST.get () in
if bLen <. aLen then begin
[@inline_let] let rLen = aLen -! bLen in
let a1 = sub a bLen rLen in
let res1 = sub res bLen rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h2 = ST.get () in
LSeq.lemma_concat2 (v bLen) (as_seq h1 res0) (v rLen) (as_seq h2 res1) (as_seq h2 res);
c1 end
else c0
inline_for_extraction noextract
val bn_sub1:
#t:limb_t
-> aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_sub1 (as_seq h0 a) b1 in
c_out == c /\ as_seq h1 res == r))
let bn_sub1 #t aLen a b1 res =
let c0 = subborrow_st (uint #t 0) a.(0ul) b1 (sub res 0ul 1ul) in
let h0 = ST.get () in
LSeq.eq_intro (LSeq.sub (as_seq h0 res) 0 1) (LSeq.create 1 (LSeq.index (as_seq h0 res) 0));
if 1ul <. aLen then begin
[@inline_let] let rLen = aLen -! 1ul in
let a1 = sub a 1ul rLen in
let res1 = sub res 1ul rLen in
let c1 = bn_sub_carry rLen a1 c0 res1 in
let h = ST.get () in
LSeq.lemma_concat2 1 (LSeq.sub (as_seq h0 res) 0 1) (v rLen) (as_seq h res1) (as_seq h res);
c1 end
else c0
inline_for_extraction noextract
val bn_add_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r)) | false | false | Hacl.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_carry:
#t:limb_t
-> aLen:size_t
-> a:lbignum t aLen
-> c_in:carry t
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h -> live h a /\ live h res /\ eq_or_disjoint a res)
(ensures fun h0 c_out h1 -> modifies (loc res) h0 h1 /\
(let c, r = S.bn_add_carry (as_seq h0 a) c_in in
c_out == c /\ as_seq h1 res == r)) | [] | Hacl.Bignum.Addition.bn_add_carry | {
"file_name": "code/bignum/Hacl.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
aLen: Lib.IntTypes.size_t ->
a: Hacl.Bignum.Definitions.lbignum t aLen ->
c_in: Hacl.Spec.Bignum.Base.carry t ->
res: Hacl.Bignum.Definitions.lbignum t aLen
-> FStar.HyperStack.ST.Stack (Hacl.Spec.Bignum.Base.carry t) | {
"end_col": 5,
"end_line": 214,
"start_col": 2,
"start_line": 192
} |
Prims.Tot | val varray (#elt: Type) (a: array elt) : Tot vprop | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm | val varray (#elt: Type) (a: array elt) : Tot vprop
let varray (#elt: Type) (a: array elt) : Tot vprop = | false | null | false | varrayp a P.full_perm | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [
"total"
] | [
"Steel.ST.Array.array",
"Steel.Array.varrayp",
"Steel.FractionalPermission.full_perm",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt) | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val varray (#elt: Type) (a: array elt) : Tot vprop | [] | Steel.Array.varray | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Steel.ST.Array.array elt -> Steel.Effect.Common.vprop | {
"end_col": 23,
"end_line": 74,
"start_col": 2,
"start_line": 74
} |
Prims.Tot | val varrayp (#elt: Type) (a: array elt) (p: P.perm) : Tot vprop | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
}) | val varrayp (#elt: Type) (a: array elt) (p: P.perm) : Tot vprop
let varrayp (#elt: Type) (a: array elt) (p: P.perm) : Tot vprop = | false | null | false | VUnit ({ hp = varrayp_hp a p; t = _; sel = varrayp_sel a p }) | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [
"total"
] | [
"Steel.ST.Array.array",
"Steel.FractionalPermission.perm",
"Steel.Effect.Common.VUnit",
"Steel.Effect.Common.Mkvprop'",
"Steel.Array.varrayp_hp",
"FStar.Seq.Properties.lseq",
"Steel.ST.Array.length",
"Steel.Array.varrayp_sel",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm) | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val varrayp (#elt: Type) (a: array elt) (p: P.perm) : Tot vprop | [] | Steel.Array.varrayp | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Steel.ST.Array.array elt -> p: Steel.FractionalPermission.perm -> Steel.Effect.Common.vprop | {
"end_col": 4,
"end_line": 59,
"start_col": 2,
"start_line": 55
} |
Prims.GTot | val asel
(#elt: Type)
(#vp: vprop)
(a: array elt)
(h: rmem vp {FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True)})
: GTot (Seq.lseq elt (length a)) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a) | val asel
(#elt: Type)
(#vp: vprop)
(a: array elt)
(h: rmem vp {FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True)})
: GTot (Seq.lseq elt (length a))
let asel
(#elt: Type)
(#vp: vprop)
(a: array elt)
(h: rmem vp {FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True)})
: GTot (Seq.lseq elt (length a)) = | false | null | false | h (varray a) | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [
"sometrivial"
] | [
"Steel.Effect.Common.vprop",
"Steel.ST.Array.array",
"Steel.Effect.Common.rmem",
"FStar.Tactics.Effect.with_tactic",
"Steel.Effect.Common.selector_tactic",
"Prims.l_and",
"Steel.Effect.Common.can_be_split",
"Steel.Array.varray",
"Prims.l_True",
"FStar.Seq.Properties.lseq",
"Steel.ST.Array.length"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) }) | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val asel
(#elt: Type)
(#vp: vprop)
(a: array elt)
(h: rmem vp {FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True)})
: GTot (Seq.lseq elt (length a)) | [] | Steel.Array.asel | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
a: Steel.ST.Array.array elt ->
h:
Steel.Effect.Common.rmem vp
{ FStar.Tactics.Effect.with_tactic Steel.Effect.Common.selector_tactic
(Steel.Effect.Common.can_be_split vp (Steel.Array.varray a) /\ Prims.l_True) }
-> Prims.GTot (FStar.Seq.Properties.lseq elt (Steel.ST.Array.length a)) | {
"end_col": 14,
"end_line": 80,
"start_col": 2,
"start_line": 80
} |
Prims.GTot | val aselp
(#elt: Type)
(#vp: vprop)
(a: array elt)
(p: P.perm)
(h:
rmem vp
{FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True)})
: GTot (Seq.lseq elt (length a)) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p) | val aselp
(#elt: Type)
(#vp: vprop)
(a: array elt)
(p: P.perm)
(h:
rmem vp
{FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True)})
: GTot (Seq.lseq elt (length a))
let aselp
(#elt: Type)
(#vp: vprop)
(a: array elt)
(p: P.perm)
(h:
rmem vp
{FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True)})
: GTot (Seq.lseq elt (length a)) = | false | null | false | h (varrayp a p) | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [
"sometrivial"
] | [
"Steel.Effect.Common.vprop",
"Steel.ST.Array.array",
"Steel.FractionalPermission.perm",
"Steel.Effect.Common.rmem",
"FStar.Tactics.Effect.with_tactic",
"Steel.Effect.Common.selector_tactic",
"Prims.l_and",
"Steel.Effect.Common.can_be_split",
"Steel.Array.varrayp",
"Prims.l_True",
"FStar.Seq.Properties.lseq",
"Steel.ST.Array.length"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) }) | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val aselp
(#elt: Type)
(#vp: vprop)
(a: array elt)
(p: P.perm)
(h:
rmem vp
{FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True)})
: GTot (Seq.lseq elt (length a)) | [] | Steel.Array.aselp | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
a: Steel.ST.Array.array elt ->
p: Steel.FractionalPermission.perm ->
h:
Steel.Effect.Common.rmem vp
{ FStar.Tactics.Effect.with_tactic Steel.Effect.Common.selector_tactic
(Steel.Effect.Common.can_be_split vp (Steel.Array.varrayp a p) /\ Prims.l_True) }
-> Prims.GTot (FStar.Seq.Properties.lseq elt (Steel.ST.Array.length a)) | {
"end_col": 17,
"end_line": 68,
"start_col": 2,
"start_line": 68
} |
Steel.Effect.Atomic.SteelGhost | val elim_varray (#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt))
opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ -> Ghost.reveal res == asel a h) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _ | val elim_varray (#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt))
opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ -> Ghost.reveal res == asel a h)
let elim_varray (#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt))
opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ -> Ghost.reveal res == asel a h) = | true | null | false | elim_varrayp _ _ | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Steel.Memory.inames",
"Steel.ST.Array.array",
"Steel.Array.elim_varrayp",
"Steel.FractionalPermission.full_perm",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.Array.varray",
"Steel.ST.Array.pts_to",
"FStar.Ghost.reveal",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.eq2",
"Steel.Array.asel"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val elim_varray (#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt))
opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ -> Ghost.reveal res == asel a h) | [] | Steel.Array.elim_varray | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Steel.ST.Array.array elt
-> Steel.Effect.Atomic.SteelGhost (FStar.Ghost.erased (FStar.Seq.Base.seq elt)) | {
"end_col": 18,
"end_line": 124,
"start_col": 2,
"start_line": 124
} |
Steel.Effect.Atomic.SteelGhost | val intro_varray (#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit
opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' -> asel a h' == s) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _ | val intro_varray (#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit
opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' -> asel a h' == s)
let intro_varray (#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit
opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' -> asel a h' == s) = | true | null | false | intro_varrayp _ _ _ | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Steel.Memory.inames",
"Steel.ST.Array.array",
"FStar.Seq.Base.seq",
"Steel.Array.intro_varrayp",
"Steel.FractionalPermission.full_perm",
"Prims.unit",
"Steel.ST.Array.pts_to",
"Steel.Array.varray",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.eq2",
"Steel.Array.asel"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_varray (#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit
opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' -> asel a h' == s) | [] | Steel.Array.intro_varray | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Steel.ST.Array.array elt -> s: FStar.Seq.Base.seq elt
-> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 21,
"end_line": 102,
"start_col": 2,
"start_line": 102
} |
Steel.Effect.SteelT | val intro_fits_ptrdiff64: unit
-> SteelT (squash (UP.fits (FStar.Int.max_int 64))) emp (fun _ -> emp) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_fits_ptrdiff64 (_:unit)
: SteelT (squash (UP.fits (FStar.Int.max_int 64)))
emp (fun _ -> emp)
= A.intro_fits_ptrdiff64 () | val intro_fits_ptrdiff64: unit
-> SteelT (squash (UP.fits (FStar.Int.max_int 64))) emp (fun _ -> emp)
let intro_fits_ptrdiff64 (_: unit)
: SteelT (squash (UP.fits (FStar.Int.max_int 64))) emp (fun _ -> emp) = | true | null | true | A.intro_fits_ptrdiff64 () | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Prims.unit",
"Steel.ST.Array.intro_fits_ptrdiff64",
"Prims.squash",
"FStar.PtrdiffT.fits",
"FStar.Int.max_int",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res
/// Freeing a full array.
inline_for_extraction
[@@ noextract_to "krml";
warn_on_use "Steel.Array.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"]
let free
(#elt: Type)
(a: array elt)
: Steel unit
(varray a)
(fun _ -> emp)
(fun _ ->
is_full_array a
)
(fun _ _ _ -> True)
= let _ = elim_varray a in
A.free a
/// Sharing and gathering permissions on an array. Those only
/// manipulate permissions, so they are nothing more than stateful
/// lemmas.
inline_for_extraction // FIXME: F* bug. This attribute is not necessary here, but if removed, F* complains about duplicate declaration and definition
let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h
)
= let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _
inline_for_extraction // same here
let gather
(#opened: _)
(#elt: Type)
(a: array elt)
(p1: P.perm)
(p2: P.perm)
: SteelGhost unit opened
(varrayp a p1 `star` varrayp a p2)
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h
)
= let _ = elim_varrayp a p1 in
let _ = elim_varrayp a p2 in
A.gather a p1 p2;
intro_varrayp a _ _
/// Reading the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let index
(#t: Type) (#p: P.perm)
(a: array t)
(i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\
US.v i < Seq.length s /\
res == Seq.index s (US.v i)
)
= let _ = elim_varrayp a p in
let res = A.index a i in
intro_varrayp a _ _;
return res
/// Writing the value v at the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let upd
(#t: Type)
(a: array t)
(i: US.t)
(v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' ->
US.v i < length a /\
asel a h' == Seq.upd (asel a h) (US.v i) v
)
= let s = elim_varray a in
A.pts_to_length a _;
A.upd a i v;
intro_varray a _
/// Spatial merging of two arrays, expressed in terms of `merge`.
inline_for_extraction // same as above
let ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit opened
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' ->
aselp (merge a1 a2) p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 p in
let _ = elim_varrayp a2 p in
A.ghost_join a1 a2 ();
intro_varrayp _ _ _
/// Spatial merging, combining the use of `merge` and the call to the
/// stateful lemma. Since the only operations are calls to stateful
/// lemmas and pure computations, the overall computation is atomic
/// and unobservable, so can be used anywhere in atomic contexts. By
/// virtue of the length being ghost, Karamel will extract this to
/// "let res = a1"
inline_for_extraction // this will extract to "let res = a1"
[@@noextract_to "krml"]
let join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1: array elt)
(a2: Ghost.erased (array elt))
: SteelAtomicBase (array elt) false opened Unobservable
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp res p)
(fun _ -> adjacent a1 a2)
(fun h res h' ->
merge_into a1 a2 res /\
aselp res p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 _ in
let _ = elim_varrayp a2 _ in
let res = A.join a1 a2 in
intro_varrayp res _ _;
return res
/// Splitting an array a at offset i, as a stateful lemma expressed in
/// terms of split_l, split_r. In the non-selector case, this stateful
/// lemma returns a proof that offset i is in bounds of the value
/// sequence, which is needed to typecheck the post-resource.
inline_for_extraction // same as above
let ghost_split
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a: array elt)
(i: US.t { US.v i <= length a })
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp (split_l a i) p `star` varrayp (split_r a i) p)
(fun _ -> True)
(fun h _ h' ->
let x = aselp a p h in
let xl = Seq.slice x 0 (US.v i) in
let xr = Seq.slice x (US.v i) (Seq.length x) in
aselp (split_l a i) p h' == xl /\
aselp (split_r a i) p h' == xr /\
x == Seq.append xl xr
)
= let _ = elim_varrayp a _ in
A.ghost_split a i;
intro_varrayp (split_l a i) _ _;
intro_varrayp (split_r a i) _ _
/// NOTE: we could implement a SteelAtomicBase Unobservable "split"
/// operation, just like "join", but we don't want it to return a pair
/// of arrays. For now we settle on explicit use of split_l, split_r.
/// Copies the contents of a0 to a1
inline_for_extraction
let memcpy (#t:_) (#p0:P.perm)
(a0 a1:array t)
(i:US.t)
: Steel unit
(varrayp a0 p0 `star` varray a1)
(fun _ -> varrayp a0 p0 `star` varray a1)
(requires fun _ ->
US.v i == length a0 /\ length a0 == length a1)
(ensures fun h0 _ h1 ->
length a0 == length a1 /\
aselp a0 p0 h0 == aselp a0 p0 h1 /\
asel a1 h1 == aselp a0 p0 h1)
=
let _ = elim_varrayp a0 _ in
let _ = elim_varray a1 in
A.memcpy a0 a1 i;
intro_varrayp a0 _ _;
intro_varray a1 _
/// Decides whether the contents of a0 and a1 are equal
inline_for_extraction
let compare (#t:eqtype) (#p0 #p1:P.perm)
(a0 a1:array t)
(l:US.t { length a0 == length a1 /\ US.v l == length a0})
: Steel bool
(varrayp a0 p0 `star` varrayp a1 p1)
(fun _ -> varrayp a0 p0 `star` varrayp a1 p1)
(requires fun _ -> True)
(ensures fun h0 b h1 ->
aselp a0 p0 h0 == aselp a0 p0 h1 /\
aselp a1 p1 h0 == aselp a1 p1 h1 /\
b = (aselp a0 p0 h1 = aselp a1 p1 h1))
=
let _ = elim_varrayp a0 _ in
let _ = elim_varrayp a1 _ in
let res = A.compare a0 a1 l in
intro_varrayp a0 _ _;
intro_varrayp a1 _ _;
return res
/// An introduction function for the fits_u32 predicate.
/// It will be natively extracted to static_assert (UINT32_MAX <= SIZE_T_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_u32 (_:unit)
: SteelT (squash (US.fits_u32))
emp (fun _ -> emp)
= A.intro_fits_u32 ()
/// An introduction function for the fits_u64 predicate.
/// It will be natively extracted to static_assert (UINT64_MAX <= SIZE_T_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_u64 (_:unit)
: SteelT (squash (US.fits_u64))
emp (fun _ -> emp)
= A.intro_fits_u64 ()
/// Determining whether int32 values fit in a ptrdiff
/// It will be natively extracted to static_assert (INT32_MAX <= PTRDIFF_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_ptrdiff32 (_:unit)
: SteelT (squash (UP.fits (FStar.Int.max_int 32)))
emp (fun _ -> emp)
= A.intro_fits_ptrdiff32 ()
/// Determining whether int64 values fit in a ptrdiff
/// It will be natively extracted to static_assert (INT64_MAX <= PTRDIFF_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_ptrdiff64 (_:unit)
: SteelT (squash (UP.fits (FStar.Int.max_int 64))) | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_fits_ptrdiff64: unit
-> SteelT (squash (UP.fits (FStar.Int.max_int 64))) emp (fun _ -> emp) | [] | Steel.Array.intro_fits_ptrdiff64 | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | _: Prims.unit -> Steel.Effect.SteelT (Prims.squash (FStar.PtrdiffT.fits (FStar.Int.max_int 64))) | {
"end_col": 29,
"end_line": 423,
"start_col": 4,
"start_line": 423
} |
Steel.Effect.SteelT | val intro_fits_u64: unit -> SteelT (squash (US.fits_u64)) emp (fun _ -> emp) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_fits_u64 (_:unit)
: SteelT (squash (US.fits_u64))
emp (fun _ -> emp)
= A.intro_fits_u64 () | val intro_fits_u64: unit -> SteelT (squash (US.fits_u64)) emp (fun _ -> emp)
let intro_fits_u64 (_: unit) : SteelT (squash (US.fits_u64)) emp (fun _ -> emp) = | true | null | true | A.intro_fits_u64 () | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Prims.unit",
"Steel.ST.Array.intro_fits_u64",
"Prims.squash",
"FStar.SizeT.fits_u64",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res
/// Freeing a full array.
inline_for_extraction
[@@ noextract_to "krml";
warn_on_use "Steel.Array.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"]
let free
(#elt: Type)
(a: array elt)
: Steel unit
(varray a)
(fun _ -> emp)
(fun _ ->
is_full_array a
)
(fun _ _ _ -> True)
= let _ = elim_varray a in
A.free a
/// Sharing and gathering permissions on an array. Those only
/// manipulate permissions, so they are nothing more than stateful
/// lemmas.
inline_for_extraction // FIXME: F* bug. This attribute is not necessary here, but if removed, F* complains about duplicate declaration and definition
let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h
)
= let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _
inline_for_extraction // same here
let gather
(#opened: _)
(#elt: Type)
(a: array elt)
(p1: P.perm)
(p2: P.perm)
: SteelGhost unit opened
(varrayp a p1 `star` varrayp a p2)
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h
)
= let _ = elim_varrayp a p1 in
let _ = elim_varrayp a p2 in
A.gather a p1 p2;
intro_varrayp a _ _
/// Reading the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let index
(#t: Type) (#p: P.perm)
(a: array t)
(i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\
US.v i < Seq.length s /\
res == Seq.index s (US.v i)
)
= let _ = elim_varrayp a p in
let res = A.index a i in
intro_varrayp a _ _;
return res
/// Writing the value v at the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let upd
(#t: Type)
(a: array t)
(i: US.t)
(v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' ->
US.v i < length a /\
asel a h' == Seq.upd (asel a h) (US.v i) v
)
= let s = elim_varray a in
A.pts_to_length a _;
A.upd a i v;
intro_varray a _
/// Spatial merging of two arrays, expressed in terms of `merge`.
inline_for_extraction // same as above
let ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit opened
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' ->
aselp (merge a1 a2) p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 p in
let _ = elim_varrayp a2 p in
A.ghost_join a1 a2 ();
intro_varrayp _ _ _
/// Spatial merging, combining the use of `merge` and the call to the
/// stateful lemma. Since the only operations are calls to stateful
/// lemmas and pure computations, the overall computation is atomic
/// and unobservable, so can be used anywhere in atomic contexts. By
/// virtue of the length being ghost, Karamel will extract this to
/// "let res = a1"
inline_for_extraction // this will extract to "let res = a1"
[@@noextract_to "krml"]
let join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1: array elt)
(a2: Ghost.erased (array elt))
: SteelAtomicBase (array elt) false opened Unobservable
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp res p)
(fun _ -> adjacent a1 a2)
(fun h res h' ->
merge_into a1 a2 res /\
aselp res p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 _ in
let _ = elim_varrayp a2 _ in
let res = A.join a1 a2 in
intro_varrayp res _ _;
return res
/// Splitting an array a at offset i, as a stateful lemma expressed in
/// terms of split_l, split_r. In the non-selector case, this stateful
/// lemma returns a proof that offset i is in bounds of the value
/// sequence, which is needed to typecheck the post-resource.
inline_for_extraction // same as above
let ghost_split
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a: array elt)
(i: US.t { US.v i <= length a })
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp (split_l a i) p `star` varrayp (split_r a i) p)
(fun _ -> True)
(fun h _ h' ->
let x = aselp a p h in
let xl = Seq.slice x 0 (US.v i) in
let xr = Seq.slice x (US.v i) (Seq.length x) in
aselp (split_l a i) p h' == xl /\
aselp (split_r a i) p h' == xr /\
x == Seq.append xl xr
)
= let _ = elim_varrayp a _ in
A.ghost_split a i;
intro_varrayp (split_l a i) _ _;
intro_varrayp (split_r a i) _ _
/// NOTE: we could implement a SteelAtomicBase Unobservable "split"
/// operation, just like "join", but we don't want it to return a pair
/// of arrays. For now we settle on explicit use of split_l, split_r.
/// Copies the contents of a0 to a1
inline_for_extraction
let memcpy (#t:_) (#p0:P.perm)
(a0 a1:array t)
(i:US.t)
: Steel unit
(varrayp a0 p0 `star` varray a1)
(fun _ -> varrayp a0 p0 `star` varray a1)
(requires fun _ ->
US.v i == length a0 /\ length a0 == length a1)
(ensures fun h0 _ h1 ->
length a0 == length a1 /\
aselp a0 p0 h0 == aselp a0 p0 h1 /\
asel a1 h1 == aselp a0 p0 h1)
=
let _ = elim_varrayp a0 _ in
let _ = elim_varray a1 in
A.memcpy a0 a1 i;
intro_varrayp a0 _ _;
intro_varray a1 _
/// Decides whether the contents of a0 and a1 are equal
inline_for_extraction
let compare (#t:eqtype) (#p0 #p1:P.perm)
(a0 a1:array t)
(l:US.t { length a0 == length a1 /\ US.v l == length a0})
: Steel bool
(varrayp a0 p0 `star` varrayp a1 p1)
(fun _ -> varrayp a0 p0 `star` varrayp a1 p1)
(requires fun _ -> True)
(ensures fun h0 b h1 ->
aselp a0 p0 h0 == aselp a0 p0 h1 /\
aselp a1 p1 h0 == aselp a1 p1 h1 /\
b = (aselp a0 p0 h1 = aselp a1 p1 h1))
=
let _ = elim_varrayp a0 _ in
let _ = elim_varrayp a1 _ in
let res = A.compare a0 a1 l in
intro_varrayp a0 _ _;
intro_varrayp a1 _ _;
return res
/// An introduction function for the fits_u32 predicate.
/// It will be natively extracted to static_assert (UINT32_MAX <= SIZE_T_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_u32 (_:unit)
: SteelT (squash (US.fits_u32))
emp (fun _ -> emp)
= A.intro_fits_u32 ()
/// An introduction function for the fits_u64 predicate.
/// It will be natively extracted to static_assert (UINT64_MAX <= SIZE_T_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_u64 (_:unit)
: SteelT (squash (US.fits_u64)) | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_fits_u64: unit -> SteelT (squash (US.fits_u64)) emp (fun _ -> emp) | [] | Steel.Array.intro_fits_u64 | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | _: Prims.unit -> Steel.Effect.SteelT (Prims.squash FStar.SizeT.fits_u64) | {
"end_col": 23,
"end_line": 405,
"start_col": 4,
"start_line": 405
} |
Steel.Effect.SteelT | val intro_fits_ptrdiff32: unit
-> SteelT (squash (UP.fits (FStar.Int.max_int 32))) emp (fun _ -> emp) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_fits_ptrdiff32 (_:unit)
: SteelT (squash (UP.fits (FStar.Int.max_int 32)))
emp (fun _ -> emp)
= A.intro_fits_ptrdiff32 () | val intro_fits_ptrdiff32: unit
-> SteelT (squash (UP.fits (FStar.Int.max_int 32))) emp (fun _ -> emp)
let intro_fits_ptrdiff32 (_: unit)
: SteelT (squash (UP.fits (FStar.Int.max_int 32))) emp (fun _ -> emp) = | true | null | true | A.intro_fits_ptrdiff32 () | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Prims.unit",
"Steel.ST.Array.intro_fits_ptrdiff32",
"Prims.squash",
"FStar.PtrdiffT.fits",
"FStar.Int.max_int",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res
/// Freeing a full array.
inline_for_extraction
[@@ noextract_to "krml";
warn_on_use "Steel.Array.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"]
let free
(#elt: Type)
(a: array elt)
: Steel unit
(varray a)
(fun _ -> emp)
(fun _ ->
is_full_array a
)
(fun _ _ _ -> True)
= let _ = elim_varray a in
A.free a
/// Sharing and gathering permissions on an array. Those only
/// manipulate permissions, so they are nothing more than stateful
/// lemmas.
inline_for_extraction // FIXME: F* bug. This attribute is not necessary here, but if removed, F* complains about duplicate declaration and definition
let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h
)
= let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _
inline_for_extraction // same here
let gather
(#opened: _)
(#elt: Type)
(a: array elt)
(p1: P.perm)
(p2: P.perm)
: SteelGhost unit opened
(varrayp a p1 `star` varrayp a p2)
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h
)
= let _ = elim_varrayp a p1 in
let _ = elim_varrayp a p2 in
A.gather a p1 p2;
intro_varrayp a _ _
/// Reading the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let index
(#t: Type) (#p: P.perm)
(a: array t)
(i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\
US.v i < Seq.length s /\
res == Seq.index s (US.v i)
)
= let _ = elim_varrayp a p in
let res = A.index a i in
intro_varrayp a _ _;
return res
/// Writing the value v at the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let upd
(#t: Type)
(a: array t)
(i: US.t)
(v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' ->
US.v i < length a /\
asel a h' == Seq.upd (asel a h) (US.v i) v
)
= let s = elim_varray a in
A.pts_to_length a _;
A.upd a i v;
intro_varray a _
/// Spatial merging of two arrays, expressed in terms of `merge`.
inline_for_extraction // same as above
let ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit opened
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' ->
aselp (merge a1 a2) p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 p in
let _ = elim_varrayp a2 p in
A.ghost_join a1 a2 ();
intro_varrayp _ _ _
/// Spatial merging, combining the use of `merge` and the call to the
/// stateful lemma. Since the only operations are calls to stateful
/// lemmas and pure computations, the overall computation is atomic
/// and unobservable, so can be used anywhere in atomic contexts. By
/// virtue of the length being ghost, Karamel will extract this to
/// "let res = a1"
inline_for_extraction // this will extract to "let res = a1"
[@@noextract_to "krml"]
let join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1: array elt)
(a2: Ghost.erased (array elt))
: SteelAtomicBase (array elt) false opened Unobservable
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp res p)
(fun _ -> adjacent a1 a2)
(fun h res h' ->
merge_into a1 a2 res /\
aselp res p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 _ in
let _ = elim_varrayp a2 _ in
let res = A.join a1 a2 in
intro_varrayp res _ _;
return res
/// Splitting an array a at offset i, as a stateful lemma expressed in
/// terms of split_l, split_r. In the non-selector case, this stateful
/// lemma returns a proof that offset i is in bounds of the value
/// sequence, which is needed to typecheck the post-resource.
inline_for_extraction // same as above
let ghost_split
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a: array elt)
(i: US.t { US.v i <= length a })
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp (split_l a i) p `star` varrayp (split_r a i) p)
(fun _ -> True)
(fun h _ h' ->
let x = aselp a p h in
let xl = Seq.slice x 0 (US.v i) in
let xr = Seq.slice x (US.v i) (Seq.length x) in
aselp (split_l a i) p h' == xl /\
aselp (split_r a i) p h' == xr /\
x == Seq.append xl xr
)
= let _ = elim_varrayp a _ in
A.ghost_split a i;
intro_varrayp (split_l a i) _ _;
intro_varrayp (split_r a i) _ _
/// NOTE: we could implement a SteelAtomicBase Unobservable "split"
/// operation, just like "join", but we don't want it to return a pair
/// of arrays. For now we settle on explicit use of split_l, split_r.
/// Copies the contents of a0 to a1
inline_for_extraction
let memcpy (#t:_) (#p0:P.perm)
(a0 a1:array t)
(i:US.t)
: Steel unit
(varrayp a0 p0 `star` varray a1)
(fun _ -> varrayp a0 p0 `star` varray a1)
(requires fun _ ->
US.v i == length a0 /\ length a0 == length a1)
(ensures fun h0 _ h1 ->
length a0 == length a1 /\
aselp a0 p0 h0 == aselp a0 p0 h1 /\
asel a1 h1 == aselp a0 p0 h1)
=
let _ = elim_varrayp a0 _ in
let _ = elim_varray a1 in
A.memcpy a0 a1 i;
intro_varrayp a0 _ _;
intro_varray a1 _
/// Decides whether the contents of a0 and a1 are equal
inline_for_extraction
let compare (#t:eqtype) (#p0 #p1:P.perm)
(a0 a1:array t)
(l:US.t { length a0 == length a1 /\ US.v l == length a0})
: Steel bool
(varrayp a0 p0 `star` varrayp a1 p1)
(fun _ -> varrayp a0 p0 `star` varrayp a1 p1)
(requires fun _ -> True)
(ensures fun h0 b h1 ->
aselp a0 p0 h0 == aselp a0 p0 h1 /\
aselp a1 p1 h0 == aselp a1 p1 h1 /\
b = (aselp a0 p0 h1 = aselp a1 p1 h1))
=
let _ = elim_varrayp a0 _ in
let _ = elim_varrayp a1 _ in
let res = A.compare a0 a1 l in
intro_varrayp a0 _ _;
intro_varrayp a1 _ _;
return res
/// An introduction function for the fits_u32 predicate.
/// It will be natively extracted to static_assert (UINT32_MAX <= SIZE_T_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_u32 (_:unit)
: SteelT (squash (US.fits_u32))
emp (fun _ -> emp)
= A.intro_fits_u32 ()
/// An introduction function for the fits_u64 predicate.
/// It will be natively extracted to static_assert (UINT64_MAX <= SIZE_T_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_u64 (_:unit)
: SteelT (squash (US.fits_u64))
emp (fun _ -> emp)
= A.intro_fits_u64 ()
/// Determining whether int32 values fit in a ptrdiff
/// It will be natively extracted to static_assert (INT32_MAX <= PTRDIFF_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_ptrdiff32 (_:unit)
: SteelT (squash (UP.fits (FStar.Int.max_int 32))) | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_fits_ptrdiff32: unit
-> SteelT (squash (UP.fits (FStar.Int.max_int 32))) emp (fun _ -> emp) | [] | Steel.Array.intro_fits_ptrdiff32 | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | _: Prims.unit -> Steel.Effect.SteelT (Prims.squash (FStar.PtrdiffT.fits (FStar.Int.max_int 32))) | {
"end_col": 29,
"end_line": 414,
"start_col": 4,
"start_line": 414
} |
Steel.Effect.SteelT | val intro_fits_u32: unit -> SteelT (squash (US.fits_u32)) emp (fun _ -> emp) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let intro_fits_u32 (_:unit)
: SteelT (squash (US.fits_u32))
emp (fun _ -> emp)
= A.intro_fits_u32 () | val intro_fits_u32: unit -> SteelT (squash (US.fits_u32)) emp (fun _ -> emp)
let intro_fits_u32 (_: unit) : SteelT (squash (US.fits_u32)) emp (fun _ -> emp) = | true | null | true | A.intro_fits_u32 () | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Prims.unit",
"Steel.ST.Array.intro_fits_u32",
"Prims.squash",
"FStar.SizeT.fits_u32",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.vprop"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res
/// Freeing a full array.
inline_for_extraction
[@@ noextract_to "krml";
warn_on_use "Steel.Array.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"]
let free
(#elt: Type)
(a: array elt)
: Steel unit
(varray a)
(fun _ -> emp)
(fun _ ->
is_full_array a
)
(fun _ _ _ -> True)
= let _ = elim_varray a in
A.free a
/// Sharing and gathering permissions on an array. Those only
/// manipulate permissions, so they are nothing more than stateful
/// lemmas.
inline_for_extraction // FIXME: F* bug. This attribute is not necessary here, but if removed, F* complains about duplicate declaration and definition
let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h
)
= let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _
inline_for_extraction // same here
let gather
(#opened: _)
(#elt: Type)
(a: array elt)
(p1: P.perm)
(p2: P.perm)
: SteelGhost unit opened
(varrayp a p1 `star` varrayp a p2)
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h
)
= let _ = elim_varrayp a p1 in
let _ = elim_varrayp a p2 in
A.gather a p1 p2;
intro_varrayp a _ _
/// Reading the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let index
(#t: Type) (#p: P.perm)
(a: array t)
(i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\
US.v i < Seq.length s /\
res == Seq.index s (US.v i)
)
= let _ = elim_varrayp a p in
let res = A.index a i in
intro_varrayp a _ _;
return res
/// Writing the value v at the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let upd
(#t: Type)
(a: array t)
(i: US.t)
(v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' ->
US.v i < length a /\
asel a h' == Seq.upd (asel a h) (US.v i) v
)
= let s = elim_varray a in
A.pts_to_length a _;
A.upd a i v;
intro_varray a _
/// Spatial merging of two arrays, expressed in terms of `merge`.
inline_for_extraction // same as above
let ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit opened
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' ->
aselp (merge a1 a2) p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 p in
let _ = elim_varrayp a2 p in
A.ghost_join a1 a2 ();
intro_varrayp _ _ _
/// Spatial merging, combining the use of `merge` and the call to the
/// stateful lemma. Since the only operations are calls to stateful
/// lemmas and pure computations, the overall computation is atomic
/// and unobservable, so can be used anywhere in atomic contexts. By
/// virtue of the length being ghost, Karamel will extract this to
/// "let res = a1"
inline_for_extraction // this will extract to "let res = a1"
[@@noextract_to "krml"]
let join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1: array elt)
(a2: Ghost.erased (array elt))
: SteelAtomicBase (array elt) false opened Unobservable
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp res p)
(fun _ -> adjacent a1 a2)
(fun h res h' ->
merge_into a1 a2 res /\
aselp res p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 _ in
let _ = elim_varrayp a2 _ in
let res = A.join a1 a2 in
intro_varrayp res _ _;
return res
/// Splitting an array a at offset i, as a stateful lemma expressed in
/// terms of split_l, split_r. In the non-selector case, this stateful
/// lemma returns a proof that offset i is in bounds of the value
/// sequence, which is needed to typecheck the post-resource.
inline_for_extraction // same as above
let ghost_split
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a: array elt)
(i: US.t { US.v i <= length a })
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp (split_l a i) p `star` varrayp (split_r a i) p)
(fun _ -> True)
(fun h _ h' ->
let x = aselp a p h in
let xl = Seq.slice x 0 (US.v i) in
let xr = Seq.slice x (US.v i) (Seq.length x) in
aselp (split_l a i) p h' == xl /\
aselp (split_r a i) p h' == xr /\
x == Seq.append xl xr
)
= let _ = elim_varrayp a _ in
A.ghost_split a i;
intro_varrayp (split_l a i) _ _;
intro_varrayp (split_r a i) _ _
/// NOTE: we could implement a SteelAtomicBase Unobservable "split"
/// operation, just like "join", but we don't want it to return a pair
/// of arrays. For now we settle on explicit use of split_l, split_r.
/// Copies the contents of a0 to a1
inline_for_extraction
let memcpy (#t:_) (#p0:P.perm)
(a0 a1:array t)
(i:US.t)
: Steel unit
(varrayp a0 p0 `star` varray a1)
(fun _ -> varrayp a0 p0 `star` varray a1)
(requires fun _ ->
US.v i == length a0 /\ length a0 == length a1)
(ensures fun h0 _ h1 ->
length a0 == length a1 /\
aselp a0 p0 h0 == aselp a0 p0 h1 /\
asel a1 h1 == aselp a0 p0 h1)
=
let _ = elim_varrayp a0 _ in
let _ = elim_varray a1 in
A.memcpy a0 a1 i;
intro_varrayp a0 _ _;
intro_varray a1 _
/// Decides whether the contents of a0 and a1 are equal
inline_for_extraction
let compare (#t:eqtype) (#p0 #p1:P.perm)
(a0 a1:array t)
(l:US.t { length a0 == length a1 /\ US.v l == length a0})
: Steel bool
(varrayp a0 p0 `star` varrayp a1 p1)
(fun _ -> varrayp a0 p0 `star` varrayp a1 p1)
(requires fun _ -> True)
(ensures fun h0 b h1 ->
aselp a0 p0 h0 == aselp a0 p0 h1 /\
aselp a1 p1 h0 == aselp a1 p1 h1 /\
b = (aselp a0 p0 h1 = aselp a1 p1 h1))
=
let _ = elim_varrayp a0 _ in
let _ = elim_varrayp a1 _ in
let res = A.compare a0 a1 l in
intro_varrayp a0 _ _;
intro_varrayp a1 _ _;
return res
/// An introduction function for the fits_u32 predicate.
/// It will be natively extracted to static_assert (UINT32_MAX <= SIZE_T_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_u32 (_:unit)
: SteelT (squash (US.fits_u32)) | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val intro_fits_u32: unit -> SteelT (squash (US.fits_u32)) emp (fun _ -> emp) | [] | Steel.Array.intro_fits_u32 | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | _: Prims.unit -> Steel.Effect.SteelT (Prims.squash FStar.SizeT.fits_u32) | {
"end_col": 23,
"end_line": 396,
"start_col": 4,
"start_line": 396
} |
Steel.Effect.Atomic.SteelGhost | val varrayp_not_null (#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit
opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' -> aselp a p h' == aselp a p h /\ a =!= null) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _ | val varrayp_not_null (#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit
opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' -> aselp a p h' == aselp a p h /\ a =!= null)
let varrayp_not_null (#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit
opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' -> aselp a p h' == aselp a p h /\ a =!= null) = | true | null | false | let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _ | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Steel.Memory.inames",
"Steel.ST.Array.array",
"Steel.FractionalPermission.perm",
"Steel.Array.intro_varrayp",
"FStar.Ghost.reveal",
"FStar.Seq.Base.seq",
"Prims.unit",
"Steel.ST.Array.pts_to_not_null",
"FStar.Ghost.erased",
"Steel.Array.elim_varrayp",
"Steel.Array.varrayp",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Properties.lseq",
"Steel.ST.Array.length",
"Steel.Array.aselp",
"Prims.l_not",
"Steel.ST.Array.null"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val varrayp_not_null (#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit
opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' -> aselp a p h' == aselp a p h /\ a =!= null) | [] | Steel.Array.varrayp_not_null | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Steel.ST.Array.array elt -> p: Steel.FractionalPermission.perm
-> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 21,
"end_line": 138,
"start_col": 1,
"start_line": 136
} |
Steel.Effect.Steel | val malloc (#elt: Type) (x: elt) (n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' -> length a == US.v n /\ is_full_array a /\ asel a h' == Seq.create (US.v n) x) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res | val malloc (#elt: Type) (x: elt) (n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' -> length a == US.v n /\ is_full_array a /\ asel a h' == Seq.create (US.v n) x)
let malloc (#elt: Type) (x: elt) (n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' -> length a == US.v n /\ is_full_array a /\ asel a h' == Seq.create (US.v n) x) = | true | null | false | let res = A.malloc x n in
intro_varray res _;
return res | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"FStar.SizeT.t",
"Steel.Effect.Atomic.return",
"Steel.ST.Array.array",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Array.varrayp",
"Steel.FractionalPermission.full_perm",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.Array.intro_varray",
"FStar.Seq.Base.create",
"FStar.SizeT.v",
"Steel.ST.Array.malloc",
"Steel.Effect.Common.emp",
"Steel.Array.varray",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"Steel.ST.Array.length",
"Steel.ST.Array.is_full_array",
"FStar.Seq.Base.seq",
"Steel.Array.asel"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val malloc (#elt: Type) (x: elt) (n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' -> length a == US.v n /\ is_full_array a /\ asel a h' == Seq.create (US.v n) x) | [] | Steel.Array.malloc | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | x: elt -> n: FStar.SizeT.t -> Steel.Effect.Steel (Steel.ST.Array.array elt) | {
"end_col": 12,
"end_line": 160,
"start_col": 1,
"start_line": 158
} |
Steel.Effect.Atomic.SteelGhost | val share (#opened: _) (#elt: Type) (a: array elt) (p p1 p2: P.perm)
: SteelGhost unit
opened
(varrayp a p)
(fun _ -> (varrayp a p1) `star` (varrayp a p2))
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' -> aselp a p1 h' == aselp a p h /\ aselp a p2 h' == aselp a p h) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h
)
= let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _ | val share (#opened: _) (#elt: Type) (a: array elt) (p p1 p2: P.perm)
: SteelGhost unit
opened
(varrayp a p)
(fun _ -> (varrayp a p1) `star` (varrayp a p2))
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' -> aselp a p1 h' == aselp a p h /\ aselp a p2 h' == aselp a p h)
let share (#opened: _) (#elt: Type) (a: array elt) (p p1 p2: P.perm)
: SteelGhost unit
opened
(varrayp a p)
(fun _ -> (varrayp a p1) `star` (varrayp a p2))
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' -> aselp a p1 h' == aselp a p h /\ aselp a p2 h' == aselp a p h) = | true | null | false | let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _ | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Steel.Memory.inames",
"Steel.ST.Array.array",
"Steel.FractionalPermission.perm",
"Steel.Array.intro_varrayp",
"FStar.Ghost.reveal",
"FStar.Seq.Base.seq",
"Prims.unit",
"Steel.ST.Array.share",
"FStar.Ghost.erased",
"Steel.Array.elim_varrayp",
"Steel.Array.varrayp",
"Steel.Effect.Common.star",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.eq2",
"Steel.FractionalPermission.sum_perm",
"Prims.l_and",
"FStar.Seq.Properties.lseq",
"Steel.ST.Array.length",
"Steel.Array.aselp"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res
/// Freeing a full array.
inline_for_extraction
[@@ noextract_to "krml";
warn_on_use "Steel.Array.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"]
let free
(#elt: Type)
(a: array elt)
: Steel unit
(varray a)
(fun _ -> emp)
(fun _ ->
is_full_array a
)
(fun _ _ _ -> True)
= let _ = elim_varray a in
A.free a
/// Sharing and gathering permissions on an array. Those only
/// manipulate permissions, so they are nothing more than stateful
/// lemmas.
inline_for_extraction // FIXME: F* bug. This attribute is not necessary here, but if removed, F* complains about duplicate declaration and definition
let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val share (#opened: _) (#elt: Type) (a: array elt) (p p1 p2: P.perm)
: SteelGhost unit
opened
(varrayp a p)
(fun _ -> (varrayp a p1) `star` (varrayp a p2))
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' -> aselp a p1 h' == aselp a p h /\ aselp a p2 h' == aselp a p h) | [] | Steel.Array.share | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
a: Steel.ST.Array.array elt ->
p: Steel.FractionalPermission.perm ->
p1: Steel.FractionalPermission.perm ->
p2: Steel.FractionalPermission.perm
-> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 22,
"end_line": 199,
"start_col": 1,
"start_line": 196
} |
Steel.Effect.Atomic.SteelGhost | val gather (#opened: _) (#elt: Type) (a: array elt) (p1 p2: P.perm)
: SteelGhost unit
opened
((varrayp a p1) `star` (varrayp a p2))
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gather
(#opened: _)
(#elt: Type)
(a: array elt)
(p1: P.perm)
(p2: P.perm)
: SteelGhost unit opened
(varrayp a p1 `star` varrayp a p2)
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h
)
= let _ = elim_varrayp a p1 in
let _ = elim_varrayp a p2 in
A.gather a p1 p2;
intro_varrayp a _ _ | val gather (#opened: _) (#elt: Type) (a: array elt) (p1 p2: P.perm)
: SteelGhost unit
opened
((varrayp a p1) `star` (varrayp a p2))
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h)
let gather (#opened: _) (#elt: Type) (a: array elt) (p1 p2: P.perm)
: SteelGhost unit
opened
((varrayp a p1) `star` (varrayp a p2))
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h) = | true | null | false | let _ = elim_varrayp a p1 in
let _ = elim_varrayp a p2 in
A.gather a p1 p2;
intro_varrayp a _ _ | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Steel.Memory.inames",
"Steel.ST.Array.array",
"Steel.FractionalPermission.perm",
"Steel.Array.intro_varrayp",
"Steel.FractionalPermission.sum_perm",
"FStar.Ghost.reveal",
"FStar.Seq.Base.seq",
"Prims.unit",
"Steel.ST.Array.gather",
"FStar.Ghost.erased",
"Steel.Array.elim_varrayp",
"Steel.Effect.Common.star",
"Steel.Array.varrayp",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Properties.lseq",
"Steel.ST.Array.length",
"Steel.Array.aselp"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res
/// Freeing a full array.
inline_for_extraction
[@@ noextract_to "krml";
warn_on_use "Steel.Array.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"]
let free
(#elt: Type)
(a: array elt)
: Steel unit
(varray a)
(fun _ -> emp)
(fun _ ->
is_full_array a
)
(fun _ _ _ -> True)
= let _ = elim_varray a in
A.free a
/// Sharing and gathering permissions on an array. Those only
/// manipulate permissions, so they are nothing more than stateful
/// lemmas.
inline_for_extraction // FIXME: F* bug. This attribute is not necessary here, but if removed, F* complains about duplicate declaration and definition
let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h
)
= let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _
inline_for_extraction // same here
let gather
(#opened: _)
(#elt: Type)
(a: array elt)
(p1: P.perm)
(p2: P.perm)
: SteelGhost unit opened
(varrayp a p1 `star` varrayp a p2)
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gather (#opened: _) (#elt: Type) (a: array elt) (p1 p2: P.perm)
: SteelGhost unit
opened
((varrayp a p1) `star` (varrayp a p2))
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h) | [] | Steel.Array.gather | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
a: Steel.ST.Array.array elt ->
p1: Steel.FractionalPermission.perm ->
p2: Steel.FractionalPermission.perm
-> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 21,
"end_line": 219,
"start_col": 1,
"start_line": 216
} |
Steel.Effect.Steel | val index (#t: Type) (#p: P.perm) (a: array t) (i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\ US.v i < Seq.length s /\ res == Seq.index s (US.v i)) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let index
(#t: Type) (#p: P.perm)
(a: array t)
(i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\
US.v i < Seq.length s /\
res == Seq.index s (US.v i)
)
= let _ = elim_varrayp a p in
let res = A.index a i in
intro_varrayp a _ _;
return res | val index (#t: Type) (#p: P.perm) (a: array t) (i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\ US.v i < Seq.length s /\ res == Seq.index s (US.v i))
let index (#t: Type) (#p: P.perm) (a: array t) (i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\ US.v i < Seq.length s /\ res == Seq.index s (US.v i)) = | true | null | false | let _ = elim_varrayp a p in
let res = A.index a i in
intro_varrayp a _ _;
return res | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Steel.FractionalPermission.perm",
"Steel.ST.Array.array",
"FStar.SizeT.t",
"Steel.Effect.Atomic.return",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Array.varrayp",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.Array.intro_varrayp",
"FStar.Ghost.reveal",
"FStar.Seq.Base.seq",
"Steel.ST.Array.index",
"FStar.Ghost.erased",
"Steel.Array.elim_varrayp",
"Steel.Effect.Common.rmem",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.SizeT.v",
"Steel.ST.Array.length",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Properties.lseq",
"Steel.Array.aselp",
"FStar.Seq.Base.length",
"FStar.Seq.Base.index"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res
/// Freeing a full array.
inline_for_extraction
[@@ noextract_to "krml";
warn_on_use "Steel.Array.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"]
let free
(#elt: Type)
(a: array elt)
: Steel unit
(varray a)
(fun _ -> emp)
(fun _ ->
is_full_array a
)
(fun _ _ _ -> True)
= let _ = elim_varray a in
A.free a
/// Sharing and gathering permissions on an array. Those only
/// manipulate permissions, so they are nothing more than stateful
/// lemmas.
inline_for_extraction // FIXME: F* bug. This attribute is not necessary here, but if removed, F* complains about duplicate declaration and definition
let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h
)
= let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _
inline_for_extraction // same here
let gather
(#opened: _)
(#elt: Type)
(a: array elt)
(p1: P.perm)
(p2: P.perm)
: SteelGhost unit opened
(varrayp a p1 `star` varrayp a p2)
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h
)
= let _ = elim_varrayp a p1 in
let _ = elim_varrayp a p2 in
A.gather a p1 p2;
intro_varrayp a _ _
/// Reading the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let index
(#t: Type) (#p: P.perm)
(a: array t)
(i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\
US.v i < Seq.length s /\
res == Seq.index s (US.v i) | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val index (#t: Type) (#p: P.perm) (a: array t) (i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\ US.v i < Seq.length s /\ res == Seq.index s (US.v i)) | [] | Steel.Array.index | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Steel.ST.Array.array t -> i: FStar.SizeT.t -> Steel.Effect.Steel t | {
"end_col": 12,
"end_line": 242,
"start_col": 1,
"start_line": 239
} |
Steel.Effect.Atomic.SteelGhost | val ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit
opened
((varrayp a1 p) `star` (varrayp a2 p))
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' -> aselp (merge a1 a2) p h' == (aselp a1 p h) `Seq.append` (aselp a2 p h)) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit opened
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' ->
aselp (merge a1 a2) p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 p in
let _ = elim_varrayp a2 p in
A.ghost_join a1 a2 ();
intro_varrayp _ _ _ | val ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit
opened
((varrayp a1 p) `star` (varrayp a2 p))
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' -> aselp (merge a1 a2) p h' == (aselp a1 p h) `Seq.append` (aselp a2 p h))
let ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit
opened
((varrayp a1 p) `star` (varrayp a2 p))
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' -> aselp (merge a1 a2) p h' == (aselp a1 p h) `Seq.append` (aselp a2 p h)) = | true | null | false | let _ = elim_varrayp a1 p in
let _ = elim_varrayp a2 p in
A.ghost_join a1 a2 ();
intro_varrayp _ _ _ | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"Steel.ST.Array.array",
"Prims.squash",
"Steel.ST.Array.adjacent",
"Steel.Array.intro_varrayp",
"Steel.ST.Array.merge",
"FStar.Ghost.hide",
"FStar.Seq.Base.append",
"FStar.Ghost.reveal",
"FStar.Seq.Base.seq",
"Prims.unit",
"Steel.ST.Array.ghost_join",
"FStar.Ghost.erased",
"Steel.Array.elim_varrayp",
"Steel.Effect.Common.star",
"Steel.Array.varrayp",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"Prims.eq2",
"Steel.Array.aselp"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res
/// Freeing a full array.
inline_for_extraction
[@@ noextract_to "krml";
warn_on_use "Steel.Array.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"]
let free
(#elt: Type)
(a: array elt)
: Steel unit
(varray a)
(fun _ -> emp)
(fun _ ->
is_full_array a
)
(fun _ _ _ -> True)
= let _ = elim_varray a in
A.free a
/// Sharing and gathering permissions on an array. Those only
/// manipulate permissions, so they are nothing more than stateful
/// lemmas.
inline_for_extraction // FIXME: F* bug. This attribute is not necessary here, but if removed, F* complains about duplicate declaration and definition
let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h
)
= let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _
inline_for_extraction // same here
let gather
(#opened: _)
(#elt: Type)
(a: array elt)
(p1: P.perm)
(p2: P.perm)
: SteelGhost unit opened
(varrayp a p1 `star` varrayp a p2)
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h
)
= let _ = elim_varrayp a p1 in
let _ = elim_varrayp a p2 in
A.gather a p1 p2;
intro_varrayp a _ _
/// Reading the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let index
(#t: Type) (#p: P.perm)
(a: array t)
(i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\
US.v i < Seq.length s /\
res == Seq.index s (US.v i)
)
= let _ = elim_varrayp a p in
let res = A.index a i in
intro_varrayp a _ _;
return res
/// Writing the value v at the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let upd
(#t: Type)
(a: array t)
(i: US.t)
(v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' ->
US.v i < length a /\
asel a h' == Seq.upd (asel a h) (US.v i) v
)
= let s = elim_varray a in
A.pts_to_length a _;
A.upd a i v;
intro_varray a _
/// Spatial merging of two arrays, expressed in terms of `merge`.
inline_for_extraction // same as above
let ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit opened
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' ->
aselp (merge a1 a2) p h' == aselp a1 p h `Seq.append` aselp a2 p h | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit
opened
((varrayp a1 p) `star` (varrayp a2 p))
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' -> aselp (merge a1 a2) p h' == (aselp a1 p h) `Seq.append` (aselp a2 p h)) | [] | Steel.Array.ghost_join | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
a1: Steel.ST.Array.array elt ->
a2: Steel.ST.Array.array elt ->
sq: Prims.squash (Steel.ST.Array.adjacent a1 a2)
-> Steel.Effect.Atomic.SteelGhost Prims.unit | {
"end_col": 21,
"end_line": 284,
"start_col": 1,
"start_line": 281
} |
Steel.Effect.Steel | val upd (#t: Type) (a: array t) (i: US.t) (v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' -> US.v i < length a /\ asel a h' == Seq.upd (asel a h) (US.v i) v) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let upd
(#t: Type)
(a: array t)
(i: US.t)
(v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' ->
US.v i < length a /\
asel a h' == Seq.upd (asel a h) (US.v i) v
)
= let s = elim_varray a in
A.pts_to_length a _;
A.upd a i v;
intro_varray a _ | val upd (#t: Type) (a: array t) (i: US.t) (v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' -> US.v i < length a /\ asel a h' == Seq.upd (asel a h) (US.v i) v)
let upd (#t: Type) (a: array t) (i: US.t) (v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' -> US.v i < length a /\ asel a h' == Seq.upd (asel a h) (US.v i) v) = | true | null | false | let s = elim_varray a in
A.pts_to_length a _;
A.upd a i v;
intro_varray a _ | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Steel.ST.Array.array",
"FStar.SizeT.t",
"Steel.Array.intro_varray",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"FStar.Seq.Base.upd",
"FStar.Ghost.reveal",
"FStar.Seq.Base.seq",
"FStar.SizeT.v",
"Prims.unit",
"Steel.ST.Array.upd",
"Steel.ST.Array.pts_to_length",
"Steel.FractionalPermission.full_perm",
"FStar.Ghost.erased",
"Steel.Array.elim_varray",
"Steel.Array.varray",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.b2t",
"Prims.op_LessThan",
"Steel.ST.Array.length",
"Prims.l_and",
"Prims.eq2",
"Steel.Array.asel"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res
/// Freeing a full array.
inline_for_extraction
[@@ noextract_to "krml";
warn_on_use "Steel.Array.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"]
let free
(#elt: Type)
(a: array elt)
: Steel unit
(varray a)
(fun _ -> emp)
(fun _ ->
is_full_array a
)
(fun _ _ _ -> True)
= let _ = elim_varray a in
A.free a
/// Sharing and gathering permissions on an array. Those only
/// manipulate permissions, so they are nothing more than stateful
/// lemmas.
inline_for_extraction // FIXME: F* bug. This attribute is not necessary here, but if removed, F* complains about duplicate declaration and definition
let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h
)
= let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _
inline_for_extraction // same here
let gather
(#opened: _)
(#elt: Type)
(a: array elt)
(p1: P.perm)
(p2: P.perm)
: SteelGhost unit opened
(varrayp a p1 `star` varrayp a p2)
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h
)
= let _ = elim_varrayp a p1 in
let _ = elim_varrayp a p2 in
A.gather a p1 p2;
intro_varrayp a _ _
/// Reading the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let index
(#t: Type) (#p: P.perm)
(a: array t)
(i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\
US.v i < Seq.length s /\
res == Seq.index s (US.v i)
)
= let _ = elim_varrayp a p in
let res = A.index a i in
intro_varrayp a _ _;
return res
/// Writing the value v at the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let upd
(#t: Type)
(a: array t)
(i: US.t)
(v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' ->
US.v i < length a /\
asel a h' == Seq.upd (asel a h) (US.v i) v | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val upd (#t: Type) (a: array t) (i: US.t) (v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' -> US.v i < length a /\ asel a h' == Seq.upd (asel a h) (US.v i) v) | [] | Steel.Array.upd | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a: Steel.ST.Array.array t -> i: FStar.SizeT.t -> v: t -> Steel.Effect.Steel Prims.unit | {
"end_col": 18,
"end_line": 264,
"start_col": 1,
"start_line": 261
} |
Steel.Effect.Atomic.SteelAtomicBase | val join (#opened: _) (#elt: Type) (#p: P.perm) (a1: array elt) (a2: Ghost.erased (array elt))
: SteelAtomicBase (array elt)
false
opened
Unobservable
((varrayp a1 p) `star` (varrayp a2 p))
(fun res -> varrayp res p)
(fun _ -> adjacent a1 a2)
(fun h res h' ->
merge_into a1 a2 res /\ aselp res p h' == (aselp a1 p h) `Seq.append` (aselp a2 p h)) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1: array elt)
(a2: Ghost.erased (array elt))
: SteelAtomicBase (array elt) false opened Unobservable
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp res p)
(fun _ -> adjacent a1 a2)
(fun h res h' ->
merge_into a1 a2 res /\
aselp res p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 _ in
let _ = elim_varrayp a2 _ in
let res = A.join a1 a2 in
intro_varrayp res _ _;
return res | val join (#opened: _) (#elt: Type) (#p: P.perm) (a1: array elt) (a2: Ghost.erased (array elt))
: SteelAtomicBase (array elt)
false
opened
Unobservable
((varrayp a1 p) `star` (varrayp a2 p))
(fun res -> varrayp res p)
(fun _ -> adjacent a1 a2)
(fun h res h' ->
merge_into a1 a2 res /\ aselp res p h' == (aselp a1 p h) `Seq.append` (aselp a2 p h))
let join (#opened: _) (#elt: Type) (#p: P.perm) (a1: array elt) (a2: Ghost.erased (array elt))
: SteelAtomicBase (array elt)
false
opened
Unobservable
((varrayp a1 p) `star` (varrayp a2 p))
(fun res -> varrayp res p)
(fun _ -> adjacent a1 a2)
(fun h res h' ->
merge_into a1 a2 res /\ aselp res p h' == (aselp a1 p h) `Seq.append` (aselp a2 p h)) = | true | null | false | let _ = elim_varrayp a1 _ in
let _ = elim_varrayp a2 _ in
let res = A.join a1 a2 in
intro_varrayp res _ _;
return res | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Steel.Memory.inames",
"Steel.FractionalPermission.perm",
"Steel.ST.Array.array",
"FStar.Ghost.erased",
"Steel.Effect.Atomic.return",
"Steel.Array.varrayp",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.Array.intro_varrayp",
"FStar.Seq.Base.append",
"FStar.Ghost.reveal",
"FStar.Seq.Base.seq",
"Steel.ST.Array.join",
"Steel.Array.elim_varrayp",
"Steel.Effect.Common.Unobservable",
"Steel.Effect.Common.star",
"Steel.Effect.Common.rmem",
"Steel.ST.Array.adjacent",
"Prims.l_and",
"Steel.ST.Array.merge_into",
"Prims.eq2",
"Steel.Array.aselp"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res
/// Freeing a full array.
inline_for_extraction
[@@ noextract_to "krml";
warn_on_use "Steel.Array.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"]
let free
(#elt: Type)
(a: array elt)
: Steel unit
(varray a)
(fun _ -> emp)
(fun _ ->
is_full_array a
)
(fun _ _ _ -> True)
= let _ = elim_varray a in
A.free a
/// Sharing and gathering permissions on an array. Those only
/// manipulate permissions, so they are nothing more than stateful
/// lemmas.
inline_for_extraction // FIXME: F* bug. This attribute is not necessary here, but if removed, F* complains about duplicate declaration and definition
let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h
)
= let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _
inline_for_extraction // same here
let gather
(#opened: _)
(#elt: Type)
(a: array elt)
(p1: P.perm)
(p2: P.perm)
: SteelGhost unit opened
(varrayp a p1 `star` varrayp a p2)
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h
)
= let _ = elim_varrayp a p1 in
let _ = elim_varrayp a p2 in
A.gather a p1 p2;
intro_varrayp a _ _
/// Reading the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let index
(#t: Type) (#p: P.perm)
(a: array t)
(i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\
US.v i < Seq.length s /\
res == Seq.index s (US.v i)
)
= let _ = elim_varrayp a p in
let res = A.index a i in
intro_varrayp a _ _;
return res
/// Writing the value v at the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let upd
(#t: Type)
(a: array t)
(i: US.t)
(v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' ->
US.v i < length a /\
asel a h' == Seq.upd (asel a h) (US.v i) v
)
= let s = elim_varray a in
A.pts_to_length a _;
A.upd a i v;
intro_varray a _
/// Spatial merging of two arrays, expressed in terms of `merge`.
inline_for_extraction // same as above
let ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit opened
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' ->
aselp (merge a1 a2) p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 p in
let _ = elim_varrayp a2 p in
A.ghost_join a1 a2 ();
intro_varrayp _ _ _
/// Spatial merging, combining the use of `merge` and the call to the
/// stateful lemma. Since the only operations are calls to stateful
/// lemmas and pure computations, the overall computation is atomic
/// and unobservable, so can be used anywhere in atomic contexts. By
/// virtue of the length being ghost, Karamel will extract this to
/// "let res = a1"
inline_for_extraction // this will extract to "let res = a1"
[@@noextract_to "krml"]
let join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1: array elt)
(a2: Ghost.erased (array elt))
: SteelAtomicBase (array elt) false opened Unobservable
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp res p)
(fun _ -> adjacent a1 a2)
(fun h res h' ->
merge_into a1 a2 res /\
aselp res p h' == aselp a1 p h `Seq.append` aselp a2 p h | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val join (#opened: _) (#elt: Type) (#p: P.perm) (a1: array elt) (a2: Ghost.erased (array elt))
: SteelAtomicBase (array elt)
false
opened
Unobservable
((varrayp a1 p) `star` (varrayp a2 p))
(fun res -> varrayp res p)
(fun _ -> adjacent a1 a2)
(fun h res h' ->
merge_into a1 a2 res /\ aselp res p h' == (aselp a1 p h) `Seq.append` (aselp a2 p h)) | [] | Steel.Array.join | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a1: Steel.ST.Array.array elt -> a2: FStar.Ghost.erased (Steel.ST.Array.array elt)
-> Steel.Effect.Atomic.SteelAtomicBase (Steel.ST.Array.array elt) | {
"end_col": 12,
"end_line": 312,
"start_col": 1,
"start_line": 308
} |
Steel.Effect.Steel | val memcpy (#t: _) (#p0: P.perm) (a0 a1: array t) (i: US.t)
: Steel unit
((varrayp a0 p0) `star` (varray a1))
(fun _ -> (varrayp a0 p0) `star` (varray a1))
(requires fun _ -> US.v i == length a0 /\ length a0 == length a1)
(ensures
fun h0 _ h1 ->
length a0 == length a1 /\ aselp a0 p0 h0 == aselp a0 p0 h1 /\ asel a1 h1 == aselp a0 p0 h1
) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let memcpy (#t:_) (#p0:P.perm)
(a0 a1:array t)
(i:US.t)
: Steel unit
(varrayp a0 p0 `star` varray a1)
(fun _ -> varrayp a0 p0 `star` varray a1)
(requires fun _ ->
US.v i == length a0 /\ length a0 == length a1)
(ensures fun h0 _ h1 ->
length a0 == length a1 /\
aselp a0 p0 h0 == aselp a0 p0 h1 /\
asel a1 h1 == aselp a0 p0 h1)
=
let _ = elim_varrayp a0 _ in
let _ = elim_varray a1 in
A.memcpy a0 a1 i;
intro_varrayp a0 _ _;
intro_varray a1 _ | val memcpy (#t: _) (#p0: P.perm) (a0 a1: array t) (i: US.t)
: Steel unit
((varrayp a0 p0) `star` (varray a1))
(fun _ -> (varrayp a0 p0) `star` (varray a1))
(requires fun _ -> US.v i == length a0 /\ length a0 == length a1)
(ensures
fun h0 _ h1 ->
length a0 == length a1 /\ aselp a0 p0 h0 == aselp a0 p0 h1 /\ asel a1 h1 == aselp a0 p0 h1
)
let memcpy (#t: _) (#p0: P.perm) (a0 a1: array t) (i: US.t)
: Steel unit
((varrayp a0 p0) `star` (varray a1))
(fun _ -> (varrayp a0 p0) `star` (varray a1))
(requires fun _ -> US.v i == length a0 /\ length a0 == length a1)
(ensures
fun h0 _ h1 ->
length a0 == length a1 /\ aselp a0 p0 h0 == aselp a0 p0 h1 /\ asel a1 h1 == aselp a0 p0 h1
) = | true | null | false | let _ = elim_varrayp a0 _ in
let _ = elim_varray a1 in
A.memcpy a0 a1 i;
intro_varrayp a0 _ _;
intro_varray a1 _ | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Steel.FractionalPermission.perm",
"Steel.ST.Array.array",
"FStar.SizeT.t",
"Steel.Array.intro_varray",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"FStar.Ghost.reveal",
"FStar.Seq.Base.seq",
"Prims.unit",
"Steel.Array.intro_varrayp",
"Steel.ST.Array.memcpy",
"FStar.Ghost.erased",
"Steel.Array.elim_varray",
"Steel.Array.elim_varrayp",
"Steel.Effect.Common.star",
"Steel.Array.varrayp",
"Steel.Array.varray",
"Steel.Effect.Common.vprop",
"Steel.Effect.Common.rmem",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"FStar.SizeT.v",
"Steel.ST.Array.length",
"FStar.Seq.Properties.lseq",
"Steel.Array.aselp",
"Steel.Array.asel"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res
/// Freeing a full array.
inline_for_extraction
[@@ noextract_to "krml";
warn_on_use "Steel.Array.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"]
let free
(#elt: Type)
(a: array elt)
: Steel unit
(varray a)
(fun _ -> emp)
(fun _ ->
is_full_array a
)
(fun _ _ _ -> True)
= let _ = elim_varray a in
A.free a
/// Sharing and gathering permissions on an array. Those only
/// manipulate permissions, so they are nothing more than stateful
/// lemmas.
inline_for_extraction // FIXME: F* bug. This attribute is not necessary here, but if removed, F* complains about duplicate declaration and definition
let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h
)
= let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _
inline_for_extraction // same here
let gather
(#opened: _)
(#elt: Type)
(a: array elt)
(p1: P.perm)
(p2: P.perm)
: SteelGhost unit opened
(varrayp a p1 `star` varrayp a p2)
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h
)
= let _ = elim_varrayp a p1 in
let _ = elim_varrayp a p2 in
A.gather a p1 p2;
intro_varrayp a _ _
/// Reading the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let index
(#t: Type) (#p: P.perm)
(a: array t)
(i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\
US.v i < Seq.length s /\
res == Seq.index s (US.v i)
)
= let _ = elim_varrayp a p in
let res = A.index a i in
intro_varrayp a _ _;
return res
/// Writing the value v at the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let upd
(#t: Type)
(a: array t)
(i: US.t)
(v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' ->
US.v i < length a /\
asel a h' == Seq.upd (asel a h) (US.v i) v
)
= let s = elim_varray a in
A.pts_to_length a _;
A.upd a i v;
intro_varray a _
/// Spatial merging of two arrays, expressed in terms of `merge`.
inline_for_extraction // same as above
let ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit opened
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' ->
aselp (merge a1 a2) p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 p in
let _ = elim_varrayp a2 p in
A.ghost_join a1 a2 ();
intro_varrayp _ _ _
/// Spatial merging, combining the use of `merge` and the call to the
/// stateful lemma. Since the only operations are calls to stateful
/// lemmas and pure computations, the overall computation is atomic
/// and unobservable, so can be used anywhere in atomic contexts. By
/// virtue of the length being ghost, Karamel will extract this to
/// "let res = a1"
inline_for_extraction // this will extract to "let res = a1"
[@@noextract_to "krml"]
let join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1: array elt)
(a2: Ghost.erased (array elt))
: SteelAtomicBase (array elt) false opened Unobservable
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp res p)
(fun _ -> adjacent a1 a2)
(fun h res h' ->
merge_into a1 a2 res /\
aselp res p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 _ in
let _ = elim_varrayp a2 _ in
let res = A.join a1 a2 in
intro_varrayp res _ _;
return res
/// Splitting an array a at offset i, as a stateful lemma expressed in
/// terms of split_l, split_r. In the non-selector case, this stateful
/// lemma returns a proof that offset i is in bounds of the value
/// sequence, which is needed to typecheck the post-resource.
inline_for_extraction // same as above
let ghost_split
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a: array elt)
(i: US.t { US.v i <= length a })
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp (split_l a i) p `star` varrayp (split_r a i) p)
(fun _ -> True)
(fun h _ h' ->
let x = aselp a p h in
let xl = Seq.slice x 0 (US.v i) in
let xr = Seq.slice x (US.v i) (Seq.length x) in
aselp (split_l a i) p h' == xl /\
aselp (split_r a i) p h' == xr /\
x == Seq.append xl xr
)
= let _ = elim_varrayp a _ in
A.ghost_split a i;
intro_varrayp (split_l a i) _ _;
intro_varrayp (split_r a i) _ _
/// NOTE: we could implement a SteelAtomicBase Unobservable "split"
/// operation, just like "join", but we don't want it to return a pair
/// of arrays. For now we settle on explicit use of split_l, split_r.
/// Copies the contents of a0 to a1
inline_for_extraction
let memcpy (#t:_) (#p0:P.perm)
(a0 a1:array t)
(i:US.t)
: Steel unit
(varrayp a0 p0 `star` varray a1)
(fun _ -> varrayp a0 p0 `star` varray a1)
(requires fun _ ->
US.v i == length a0 /\ length a0 == length a1)
(ensures fun h0 _ h1 ->
length a0 == length a1 /\
aselp a0 p0 h0 == aselp a0 p0 h1 /\ | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val memcpy (#t: _) (#p0: P.perm) (a0 a1: array t) (i: US.t)
: Steel unit
((varrayp a0 p0) `star` (varray a1))
(fun _ -> (varrayp a0 p0) `star` (varray a1))
(requires fun _ -> US.v i == length a0 /\ length a0 == length a1)
(ensures
fun h0 _ h1 ->
length a0 == length a1 /\ aselp a0 p0 h0 == aselp a0 p0 h1 /\ asel a1 h1 == aselp a0 p0 h1
) | [] | Steel.Array.memcpy | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | a0: Steel.ST.Array.array t -> a1: Steel.ST.Array.array t -> i: FStar.SizeT.t
-> Steel.Effect.Steel Prims.unit | {
"end_col": 21,
"end_line": 366,
"start_col": 3,
"start_line": 361
} |
Steel.Effect.Steel | val ptrdiff (#a: Type) (#p1 #p2: P.perm) (arr1 arr2: array a)
: Steel UP.t
((varrayp arr1 p1) `star` (varrayp arr2 p2))
(fun _ -> (varrayp arr1 p1) `star` (varrayp arr2 p2))
(requires
fun _ ->
base (ptr_of arr1) == base (ptr_of arr2) /\
UP.fits (offset (ptr_of arr1) - offset (ptr_of arr2)))
(ensures
fun h0 r h1 ->
aselp arr1 p1 h1 == aselp arr1 p1 h0 /\ aselp arr2 p2 h1 == aselp arr2 p2 h0 /\
UP.v r == offset (ptr_of arr1) - offset (ptr_of arr2)) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ptrdiff (#a: Type) (#p1 #p2:P.perm) (arr1 arr2: array a)
: Steel UP.t
(varrayp arr1 p1 `star` varrayp arr2 p2)
(fun _ -> varrayp arr1 p1 `star` varrayp arr2 p2)
(requires fun _ ->
base (ptr_of arr1) == base (ptr_of arr2) /\
UP.fits (offset (ptr_of arr1) - offset (ptr_of arr2)))
(ensures fun h0 r h1 ->
aselp arr1 p1 h1 == aselp arr1 p1 h0 /\
aselp arr2 p2 h1 == aselp arr2 p2 h0 /\
UP.v r == offset (ptr_of arr1) - offset (ptr_of arr2)
)
= let _ = elim_varrayp arr1 p1 in
let _ = elim_varrayp arr2 p2 in
let res = A.ptrdiff arr1 arr2 in
intro_varrayp arr1 _ _;
intro_varrayp arr2 _ _;
return res | val ptrdiff (#a: Type) (#p1 #p2: P.perm) (arr1 arr2: array a)
: Steel UP.t
((varrayp arr1 p1) `star` (varrayp arr2 p2))
(fun _ -> (varrayp arr1 p1) `star` (varrayp arr2 p2))
(requires
fun _ ->
base (ptr_of arr1) == base (ptr_of arr2) /\
UP.fits (offset (ptr_of arr1) - offset (ptr_of arr2)))
(ensures
fun h0 r h1 ->
aselp arr1 p1 h1 == aselp arr1 p1 h0 /\ aselp arr2 p2 h1 == aselp arr2 p2 h0 /\
UP.v r == offset (ptr_of arr1) - offset (ptr_of arr2))
let ptrdiff (#a: Type) (#p1 #p2: P.perm) (arr1 arr2: array a)
: Steel UP.t
((varrayp arr1 p1) `star` (varrayp arr2 p2))
(fun _ -> (varrayp arr1 p1) `star` (varrayp arr2 p2))
(requires
fun _ ->
base (ptr_of arr1) == base (ptr_of arr2) /\
UP.fits (offset (ptr_of arr1) - offset (ptr_of arr2)))
(ensures
fun h0 r h1 ->
aselp arr1 p1 h1 == aselp arr1 p1 h0 /\ aselp arr2 p2 h1 == aselp arr2 p2 h0 /\
UP.v r == offset (ptr_of arr1) - offset (ptr_of arr2)) = | true | null | false | let _ = elim_varrayp arr1 p1 in
let _ = elim_varrayp arr2 p2 in
let res = A.ptrdiff arr1 arr2 in
intro_varrayp arr1 _ _;
intro_varrayp arr2 _ _;
return res | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Steel.FractionalPermission.perm",
"Steel.ST.Array.array",
"Steel.Effect.Atomic.return",
"FStar.PtrdiffT.t",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Effect.Common.VStar",
"Steel.Array.varrayp",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.Array.intro_varrayp",
"FStar.Ghost.reveal",
"FStar.Seq.Base.seq",
"Steel.ST.Array.ptrdiff",
"FStar.Ghost.erased",
"Steel.Array.elim_varrayp",
"Steel.Effect.Common.star",
"Steel.Effect.Common.rmem",
"Prims.l_and",
"Prims.eq2",
"Steel.ST.Array.base_t",
"Steel.ST.Array.base",
"Steel.ST.Array.ptr_of",
"FStar.PtrdiffT.fits",
"Prims.op_Subtraction",
"Steel.ST.Array.offset",
"FStar.Seq.Properties.lseq",
"Steel.ST.Array.length",
"Steel.Array.aselp",
"Prims.int",
"FStar.PtrdiffT.v"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res
/// Freeing a full array.
inline_for_extraction
[@@ noextract_to "krml";
warn_on_use "Steel.Array.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"]
let free
(#elt: Type)
(a: array elt)
: Steel unit
(varray a)
(fun _ -> emp)
(fun _ ->
is_full_array a
)
(fun _ _ _ -> True)
= let _ = elim_varray a in
A.free a
/// Sharing and gathering permissions on an array. Those only
/// manipulate permissions, so they are nothing more than stateful
/// lemmas.
inline_for_extraction // FIXME: F* bug. This attribute is not necessary here, but if removed, F* complains about duplicate declaration and definition
let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h
)
= let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _
inline_for_extraction // same here
let gather
(#opened: _)
(#elt: Type)
(a: array elt)
(p1: P.perm)
(p2: P.perm)
: SteelGhost unit opened
(varrayp a p1 `star` varrayp a p2)
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h
)
= let _ = elim_varrayp a p1 in
let _ = elim_varrayp a p2 in
A.gather a p1 p2;
intro_varrayp a _ _
/// Reading the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let index
(#t: Type) (#p: P.perm)
(a: array t)
(i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\
US.v i < Seq.length s /\
res == Seq.index s (US.v i)
)
= let _ = elim_varrayp a p in
let res = A.index a i in
intro_varrayp a _ _;
return res
/// Writing the value v at the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let upd
(#t: Type)
(a: array t)
(i: US.t)
(v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' ->
US.v i < length a /\
asel a h' == Seq.upd (asel a h) (US.v i) v
)
= let s = elim_varray a in
A.pts_to_length a _;
A.upd a i v;
intro_varray a _
/// Spatial merging of two arrays, expressed in terms of `merge`.
inline_for_extraction // same as above
let ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit opened
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' ->
aselp (merge a1 a2) p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 p in
let _ = elim_varrayp a2 p in
A.ghost_join a1 a2 ();
intro_varrayp _ _ _
/// Spatial merging, combining the use of `merge` and the call to the
/// stateful lemma. Since the only operations are calls to stateful
/// lemmas and pure computations, the overall computation is atomic
/// and unobservable, so can be used anywhere in atomic contexts. By
/// virtue of the length being ghost, Karamel will extract this to
/// "let res = a1"
inline_for_extraction // this will extract to "let res = a1"
[@@noextract_to "krml"]
let join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1: array elt)
(a2: Ghost.erased (array elt))
: SteelAtomicBase (array elt) false opened Unobservable
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp res p)
(fun _ -> adjacent a1 a2)
(fun h res h' ->
merge_into a1 a2 res /\
aselp res p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 _ in
let _ = elim_varrayp a2 _ in
let res = A.join a1 a2 in
intro_varrayp res _ _;
return res
/// Splitting an array a at offset i, as a stateful lemma expressed in
/// terms of split_l, split_r. In the non-selector case, this stateful
/// lemma returns a proof that offset i is in bounds of the value
/// sequence, which is needed to typecheck the post-resource.
inline_for_extraction // same as above
let ghost_split
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a: array elt)
(i: US.t { US.v i <= length a })
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp (split_l a i) p `star` varrayp (split_r a i) p)
(fun _ -> True)
(fun h _ h' ->
let x = aselp a p h in
let xl = Seq.slice x 0 (US.v i) in
let xr = Seq.slice x (US.v i) (Seq.length x) in
aselp (split_l a i) p h' == xl /\
aselp (split_r a i) p h' == xr /\
x == Seq.append xl xr
)
= let _ = elim_varrayp a _ in
A.ghost_split a i;
intro_varrayp (split_l a i) _ _;
intro_varrayp (split_r a i) _ _
/// NOTE: we could implement a SteelAtomicBase Unobservable "split"
/// operation, just like "join", but we don't want it to return a pair
/// of arrays. For now we settle on explicit use of split_l, split_r.
/// Copies the contents of a0 to a1
inline_for_extraction
let memcpy (#t:_) (#p0:P.perm)
(a0 a1:array t)
(i:US.t)
: Steel unit
(varrayp a0 p0 `star` varray a1)
(fun _ -> varrayp a0 p0 `star` varray a1)
(requires fun _ ->
US.v i == length a0 /\ length a0 == length a1)
(ensures fun h0 _ h1 ->
length a0 == length a1 /\
aselp a0 p0 h0 == aselp a0 p0 h1 /\
asel a1 h1 == aselp a0 p0 h1)
=
let _ = elim_varrayp a0 _ in
let _ = elim_varray a1 in
A.memcpy a0 a1 i;
intro_varrayp a0 _ _;
intro_varray a1 _
/// Decides whether the contents of a0 and a1 are equal
inline_for_extraction
let compare (#t:eqtype) (#p0 #p1:P.perm)
(a0 a1:array t)
(l:US.t { length a0 == length a1 /\ US.v l == length a0})
: Steel bool
(varrayp a0 p0 `star` varrayp a1 p1)
(fun _ -> varrayp a0 p0 `star` varrayp a1 p1)
(requires fun _ -> True)
(ensures fun h0 b h1 ->
aselp a0 p0 h0 == aselp a0 p0 h1 /\
aselp a1 p1 h0 == aselp a1 p1 h1 /\
b = (aselp a0 p0 h1 = aselp a1 p1 h1))
=
let _ = elim_varrayp a0 _ in
let _ = elim_varrayp a1 _ in
let res = A.compare a0 a1 l in
intro_varrayp a0 _ _;
intro_varrayp a1 _ _;
return res
/// An introduction function for the fits_u32 predicate.
/// It will be natively extracted to static_assert (UINT32_MAX <= SIZE_T_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_u32 (_:unit)
: SteelT (squash (US.fits_u32))
emp (fun _ -> emp)
= A.intro_fits_u32 ()
/// An introduction function for the fits_u64 predicate.
/// It will be natively extracted to static_assert (UINT64_MAX <= SIZE_T_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_u64 (_:unit)
: SteelT (squash (US.fits_u64))
emp (fun _ -> emp)
= A.intro_fits_u64 ()
/// Determining whether int32 values fit in a ptrdiff
/// It will be natively extracted to static_assert (INT32_MAX <= PTRDIFF_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_ptrdiff32 (_:unit)
: SteelT (squash (UP.fits (FStar.Int.max_int 32)))
emp (fun _ -> emp)
= A.intro_fits_ptrdiff32 ()
/// Determining whether int64 values fit in a ptrdiff
/// It will be natively extracted to static_assert (INT64_MAX <= PTRDIFF_MAX) by krml
inline_for_extraction
[@@noextract_to "krml"]
let intro_fits_ptrdiff64 (_:unit)
: SteelT (squash (UP.fits (FStar.Int.max_int 64)))
emp (fun _ -> emp)
= A.intro_fits_ptrdiff64 ()
inline_for_extraction
[@@noextract_to "krml"]
let ptrdiff (#a: Type) (#p1 #p2:P.perm) (arr1 arr2: array a)
: Steel UP.t
(varrayp arr1 p1 `star` varrayp arr2 p2)
(fun _ -> varrayp arr1 p1 `star` varrayp arr2 p2)
(requires fun _ ->
base (ptr_of arr1) == base (ptr_of arr2) /\
UP.fits (offset (ptr_of arr1) - offset (ptr_of arr2)))
(ensures fun h0 r h1 ->
aselp arr1 p1 h1 == aselp arr1 p1 h0 /\
aselp arr2 p2 h1 == aselp arr2 p2 h0 /\
UP.v r == offset (ptr_of arr1) - offset (ptr_of arr2) | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ptrdiff (#a: Type) (#p1 #p2: P.perm) (arr1 arr2: array a)
: Steel UP.t
((varrayp arr1 p1) `star` (varrayp arr2 p2))
(fun _ -> (varrayp arr1 p1) `star` (varrayp arr2 p2))
(requires
fun _ ->
base (ptr_of arr1) == base (ptr_of arr2) /\
UP.fits (offset (ptr_of arr1) - offset (ptr_of arr2)))
(ensures
fun h0 r h1 ->
aselp arr1 p1 h1 == aselp arr1 p1 h0 /\ aselp arr2 p2 h1 == aselp arr2 p2 h0 /\
UP.v r == offset (ptr_of arr1) - offset (ptr_of arr2)) | [] | Steel.Array.ptrdiff | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | arr1: Steel.ST.Array.array a -> arr2: Steel.ST.Array.array a -> Steel.Effect.Steel FStar.PtrdiffT.t | {
"end_col": 14,
"end_line": 444,
"start_col": 3,
"start_line": 439
} |
Steel.Effect.Steel | val compare
(#t: eqtype)
(#p0 #p1: P.perm)
(a0 a1: array t)
(l: US.t{length a0 == length a1 /\ US.v l == length a0})
: Steel bool
((varrayp a0 p0) `star` (varrayp a1 p1))
(fun _ -> (varrayp a0 p0) `star` (varrayp a1 p1))
(requires fun _ -> True)
(ensures
fun h0 b h1 ->
aselp a0 p0 h0 == aselp a0 p0 h1 /\ aselp a1 p1 h0 == aselp a1 p1 h1 /\
b = (aselp a0 p0 h1 = aselp a1 p1 h1)) | [
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.PtrdiffT",
"short_module": "UP"
},
{
"abbrev": true,
"full_module": "FStar.SizeT",
"short_module": "US"
},
{
"abbrev": true,
"full_module": "Steel.FractionalPermission",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Steel.ST.Coercions",
"short_module": "STC"
},
{
"abbrev": false,
"full_module": "Steel.ST.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Effect.Atomic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.Memory",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let compare (#t:eqtype) (#p0 #p1:P.perm)
(a0 a1:array t)
(l:US.t { length a0 == length a1 /\ US.v l == length a0})
: Steel bool
(varrayp a0 p0 `star` varrayp a1 p1)
(fun _ -> varrayp a0 p0 `star` varrayp a1 p1)
(requires fun _ -> True)
(ensures fun h0 b h1 ->
aselp a0 p0 h0 == aselp a0 p0 h1 /\
aselp a1 p1 h0 == aselp a1 p1 h1 /\
b = (aselp a0 p0 h1 = aselp a1 p1 h1))
=
let _ = elim_varrayp a0 _ in
let _ = elim_varrayp a1 _ in
let res = A.compare a0 a1 l in
intro_varrayp a0 _ _;
intro_varrayp a1 _ _;
return res | val compare
(#t: eqtype)
(#p0 #p1: P.perm)
(a0 a1: array t)
(l: US.t{length a0 == length a1 /\ US.v l == length a0})
: Steel bool
((varrayp a0 p0) `star` (varrayp a1 p1))
(fun _ -> (varrayp a0 p0) `star` (varrayp a1 p1))
(requires fun _ -> True)
(ensures
fun h0 b h1 ->
aselp a0 p0 h0 == aselp a0 p0 h1 /\ aselp a1 p1 h0 == aselp a1 p1 h1 /\
b = (aselp a0 p0 h1 = aselp a1 p1 h1))
let compare
(#t: eqtype)
(#p0 #p1: P.perm)
(a0 a1: array t)
(l: US.t{length a0 == length a1 /\ US.v l == length a0})
: Steel bool
((varrayp a0 p0) `star` (varrayp a1 p1))
(fun _ -> (varrayp a0 p0) `star` (varrayp a1 p1))
(requires fun _ -> True)
(ensures
fun h0 b h1 ->
aselp a0 p0 h0 == aselp a0 p0 h1 /\ aselp a1 p1 h0 == aselp a1 p1 h1 /\
b = (aselp a0 p0 h1 = aselp a1 p1 h1)) = | true | null | false | let _ = elim_varrayp a0 _ in
let _ = elim_varrayp a1 _ in
let res = A.compare a0 a1 l in
intro_varrayp a0 _ _;
intro_varrayp a1 _ _;
return res | {
"checked_file": "Steel.Array.fsti.checked",
"dependencies": [
"Steel.ST.Coercions.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Memory.fsti.checked",
"Steel.FractionalPermission.fst.checked",
"Steel.Effect.Atomic.fsti.checked",
"Steel.Effect.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.fst.checked",
"FStar.SizeT.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.PtrdiffT.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Int.fsti.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.Array.fsti"
} | [] | [
"Prims.eqtype",
"Steel.FractionalPermission.perm",
"Steel.ST.Array.array",
"FStar.SizeT.t",
"Prims.l_and",
"Prims.eq2",
"Prims.nat",
"Steel.ST.Array.length",
"FStar.SizeT.v",
"Steel.Effect.Atomic.return",
"Prims.bool",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Steel.Effect.Common.VStar",
"Steel.Array.varrayp",
"Steel.Effect.Common.vprop",
"Prims.unit",
"Steel.Array.intro_varrayp",
"FStar.Ghost.reveal",
"FStar.Seq.Base.seq",
"Steel.ST.Array.compare",
"FStar.Ghost.erased",
"Steel.Array.elim_varrayp",
"Steel.Effect.Common.star",
"Steel.Effect.Common.rmem",
"Prims.l_True",
"FStar.Seq.Properties.lseq",
"Steel.Array.aselp",
"Prims.b2t",
"Prims.op_Equality"
] | [] | (*
Copyright 2020, 2021, 2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.Array
open Steel.Memory
open Steel.Effect.Atomic
open Steel.Effect
include Steel.ST.Array
/// C arrays of universe 0 elements, with selectors.
/// Non-selector style universe 0 arrays are defined in Steel.ST, but
/// we want to transparently reuse the corresponding operations in
/// Steel, so we need to bring in the lift from Steel.ST to Steel,
/// defined in Steel.ST.Coercions.
module STC = Steel.ST.Coercions
module P = Steel.FractionalPermission
module US = FStar.SizeT
module UP = FStar.PtrdiffT
module A = Steel.ST.Array
/// A selector version
/// Separation logic predicate indicating the validity of the array in the current memory, p is the fractional permission on the array
val varrayp_hp
(#elt: Type0) (a: array elt) (p: P.perm)
: Tot (slprop u#1)
/// Selector for Steel arrays. It returns the contents in memory of the array
val varrayp_sel
(#elt: Type) (a: array elt) (p: P.perm)
: Tot (selector (Seq.lseq elt (length a)) (varrayp_hp a p))
/// Combining the elements above to create an array vprop
[@__steel_reduce__] // for t_of
let varrayp
(#elt: Type) (a: array elt) (p: P.perm)
: Tot vprop
= VUnit ({
hp = varrayp_hp a p;
t = _;
sel = varrayp_sel a p;
})
/// A wrapper to access an array selector more easily.
/// Ensuring that the corresponding array vprop is in the context is done by
/// calling a variant of the framing tactic, as defined in Steel.Effect.Common
[@@ __steel_reduce__]
let aselp (#elt: Type) (#vp: vprop) (a: array elt) (p: P.perm)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varrayp a p) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varrayp a p)
[@@__steel_reduce__; __reduce__]
let varray
(#elt: Type) (a: array elt)
: Tot vprop
= varrayp a P.full_perm
[@@ __steel_reduce__]
let asel (#elt: Type) (#vp: vprop) (a: array elt)
(h: rmem vp { FStar.Tactics.with_tactic selector_tactic (can_be_split vp (varray a) /\ True) })
: GTot (Seq.lseq elt (length a))
= h (varray a)
/// Converting a `pts_to` to a `varrayp`
val intro_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a p s)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun _ _ h' ->
aselp a p h' == s
)
let intro_varray
(#opened: _) (#elt: Type) (a: array elt) (s: Seq.seq elt)
: SteelGhost unit opened
(pts_to a P.full_perm s)
(fun _ -> varray a)
(fun _ -> True)
(fun _ _ h' ->
asel a h' == s
)
= intro_varrayp _ _ _
/// Converting a `varrayp` into a `pts_to`
val elim_varrayp
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varrayp a p)
(fun res -> pts_to a p res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == aselp a p h
)
let elim_varray
(#opened: _) (#elt: Type) (a: array elt)
: SteelGhost (Ghost.erased (Seq.seq elt)) opened
(varray a)
(fun res -> pts_to a P.full_perm res)
(fun _ -> True)
(fun h res _ ->
Ghost.reveal res == asel a h
)
= elim_varrayp _ _
let varrayp_not_null
(#opened: _) (#elt: Type) (a: array elt) (p: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> True)
(fun h _ h' ->
aselp a p h' == aselp a p h /\
a =!= null
)
= let _ = elim_varrayp a p in
pts_to_not_null a _;
intro_varrayp a p _
/// Allocating a new array of size n, where each cell is initialized
/// with value x. We define the non-selector version of this operation
/// (and others) with a _pt suffix in the name.
inline_for_extraction
[@@noextract_to "krml"]
let malloc
(#elt: Type)
(x: elt)
(n: US.t)
: Steel (array elt)
emp
(fun a -> varray a)
(fun _ -> True)
(fun _ a h' ->
length a == US.v n /\
is_full_array a /\
asel a h' == Seq.create (US.v n) x
)
= let res = A.malloc x n in
intro_varray res _;
return res
/// Freeing a full array.
inline_for_extraction
[@@ noextract_to "krml";
warn_on_use "Steel.Array.free is currently unsound in the presence of zero-size subarrays, have you collected them all?"]
let free
(#elt: Type)
(a: array elt)
: Steel unit
(varray a)
(fun _ -> emp)
(fun _ ->
is_full_array a
)
(fun _ _ _ -> True)
= let _ = elim_varray a in
A.free a
/// Sharing and gathering permissions on an array. Those only
/// manipulate permissions, so they are nothing more than stateful
/// lemmas.
inline_for_extraction // FIXME: F* bug. This attribute is not necessary here, but if removed, F* complains about duplicate declaration and definition
let share
(#opened: _)
(#elt: Type)
(a: array elt)
(p p1 p2: P.perm)
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp a p1 `star` varrayp a p2)
(fun _ -> p == p1 `P.sum_perm` p2)
(fun h _ h' ->
aselp a p1 h' == aselp a p h /\
aselp a p2 h' == aselp a p h
)
= let _ = elim_varrayp a p in
A.share a p p1 p2;
intro_varrayp a p1 _;
intro_varrayp a p2 _
inline_for_extraction // same here
let gather
(#opened: _)
(#elt: Type)
(a: array elt)
(p1: P.perm)
(p2: P.perm)
: SteelGhost unit opened
(varrayp a p1 `star` varrayp a p2)
(fun _ -> varrayp a (p1 `P.sum_perm` p2))
(fun _ -> True)
(fun h _ h' ->
aselp a (p1 `P.sum_perm` p2) h' == aselp a p1 h /\
aselp a (p1 `P.sum_perm` p2) h' == aselp a p2 h
)
= let _ = elim_varrayp a p1 in
let _ = elim_varrayp a p2 in
A.gather a p1 p2;
intro_varrayp a _ _
/// Reading the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let index
(#t: Type) (#p: P.perm)
(a: array t)
(i: US.t)
: Steel t
(varrayp a p)
(fun _ -> varrayp a p)
(fun _ -> US.v i < length a)
(fun h res h' ->
let s = aselp a p h in
aselp a p h' == s /\
US.v i < Seq.length s /\
res == Seq.index s (US.v i)
)
= let _ = elim_varrayp a p in
let res = A.index a i in
intro_varrayp a _ _;
return res
/// Writing the value v at the i-th element of an array a.
/// TODO: we should also provide an atomic version for small types.
inline_for_extraction
[@@noextract_to "krml"]
let upd
(#t: Type)
(a: array t)
(i: US.t)
(v: t)
: Steel unit
(varray a)
(fun _ -> varray a)
(fun _ -> US.v i < length a)
(fun h _ h' ->
US.v i < length a /\
asel a h' == Seq.upd (asel a h) (US.v i) v
)
= let s = elim_varray a in
A.pts_to_length a _;
A.upd a i v;
intro_varray a _
/// Spatial merging of two arrays, expressed in terms of `merge`.
inline_for_extraction // same as above
let ghost_join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1 a2: array elt)
(sq: squash (adjacent a1 a2))
: SteelGhost unit opened
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp (merge a1 a2) p)
(fun _ -> True)
(fun h _ h' ->
aselp (merge a1 a2) p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 p in
let _ = elim_varrayp a2 p in
A.ghost_join a1 a2 ();
intro_varrayp _ _ _
/// Spatial merging, combining the use of `merge` and the call to the
/// stateful lemma. Since the only operations are calls to stateful
/// lemmas and pure computations, the overall computation is atomic
/// and unobservable, so can be used anywhere in atomic contexts. By
/// virtue of the length being ghost, Karamel will extract this to
/// "let res = a1"
inline_for_extraction // this will extract to "let res = a1"
[@@noextract_to "krml"]
let join
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a1: array elt)
(a2: Ghost.erased (array elt))
: SteelAtomicBase (array elt) false opened Unobservable
(varrayp a1 p `star` varrayp a2 p)
(fun res -> varrayp res p)
(fun _ -> adjacent a1 a2)
(fun h res h' ->
merge_into a1 a2 res /\
aselp res p h' == aselp a1 p h `Seq.append` aselp a2 p h
)
= let _ = elim_varrayp a1 _ in
let _ = elim_varrayp a2 _ in
let res = A.join a1 a2 in
intro_varrayp res _ _;
return res
/// Splitting an array a at offset i, as a stateful lemma expressed in
/// terms of split_l, split_r. In the non-selector case, this stateful
/// lemma returns a proof that offset i is in bounds of the value
/// sequence, which is needed to typecheck the post-resource.
inline_for_extraction // same as above
let ghost_split
(#opened: _)
(#elt: Type)
(#p: P.perm)
(a: array elt)
(i: US.t { US.v i <= length a })
: SteelGhost unit opened
(varrayp a p)
(fun _ -> varrayp (split_l a i) p `star` varrayp (split_r a i) p)
(fun _ -> True)
(fun h _ h' ->
let x = aselp a p h in
let xl = Seq.slice x 0 (US.v i) in
let xr = Seq.slice x (US.v i) (Seq.length x) in
aselp (split_l a i) p h' == xl /\
aselp (split_r a i) p h' == xr /\
x == Seq.append xl xr
)
= let _ = elim_varrayp a _ in
A.ghost_split a i;
intro_varrayp (split_l a i) _ _;
intro_varrayp (split_r a i) _ _
/// NOTE: we could implement a SteelAtomicBase Unobservable "split"
/// operation, just like "join", but we don't want it to return a pair
/// of arrays. For now we settle on explicit use of split_l, split_r.
/// Copies the contents of a0 to a1
inline_for_extraction
let memcpy (#t:_) (#p0:P.perm)
(a0 a1:array t)
(i:US.t)
: Steel unit
(varrayp a0 p0 `star` varray a1)
(fun _ -> varrayp a0 p0 `star` varray a1)
(requires fun _ ->
US.v i == length a0 /\ length a0 == length a1)
(ensures fun h0 _ h1 ->
length a0 == length a1 /\
aselp a0 p0 h0 == aselp a0 p0 h1 /\
asel a1 h1 == aselp a0 p0 h1)
=
let _ = elim_varrayp a0 _ in
let _ = elim_varray a1 in
A.memcpy a0 a1 i;
intro_varrayp a0 _ _;
intro_varray a1 _
/// Decides whether the contents of a0 and a1 are equal
inline_for_extraction
let compare (#t:eqtype) (#p0 #p1:P.perm)
(a0 a1:array t)
(l:US.t { length a0 == length a1 /\ US.v l == length a0})
: Steel bool
(varrayp a0 p0 `star` varrayp a1 p1)
(fun _ -> varrayp a0 p0 `star` varrayp a1 p1)
(requires fun _ -> True)
(ensures fun h0 b h1 ->
aselp a0 p0 h0 == aselp a0 p0 h1 /\
aselp a1 p1 h0 == aselp a1 p1 h1 /\ | false | false | Steel.Array.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val compare
(#t: eqtype)
(#p0 #p1: P.perm)
(a0 a1: array t)
(l: US.t{length a0 == length a1 /\ US.v l == length a0})
: Steel bool
((varrayp a0 p0) `star` (varrayp a1 p1))
(fun _ -> (varrayp a0 p0) `star` (varrayp a1 p1))
(requires fun _ -> True)
(ensures
fun h0 b h1 ->
aselp a0 p0 h0 == aselp a0 p0 h1 /\ aselp a1 p1 h0 == aselp a1 p1 h1 /\
b = (aselp a0 p0 h1 = aselp a1 p1 h1)) | [] | Steel.Array.compare | {
"file_name": "lib/steel/Steel.Array.fsti",
"git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} |
a0: Steel.ST.Array.array t ->
a1: Steel.ST.Array.array t ->
l:
FStar.SizeT.t
{ Steel.ST.Array.length a0 == Steel.ST.Array.length a1 /\
FStar.SizeT.v l == Steel.ST.Array.length a0 }
-> Steel.Effect.Steel Prims.bool | {
"end_col": 14,
"end_line": 387,
"start_col": 3,
"start_line": 381
} |
Prims.Tot | val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i] | val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = | false | null | false | subborrow c a.[ i ] b.[ i ] | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Spec.Bignum.Base.subborrow",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"FStar.Pervasives.Native.tuple2"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t | [] | Hacl.Spec.Bignum.Addition.bn_sub_f | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
b: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
i: Lib.IntTypes.size_nat{i < aLen} ->
c: Hacl.Spec.Bignum.Base.carry t
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.limb t | {
"end_col": 55,
"end_line": 22,
"start_col": 32,
"start_line": 22
} |
Prims.Tot | val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i] | val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = | false | null | false | addcarry c a.[ i ] b.[ i ] | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Spec.Bignum.Base.addcarry",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"FStar.Pervasives.Native.tuple2"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t | [] | Hacl.Spec.Bignum.Addition.bn_add_f | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
b: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
i: Lib.IntTypes.size_nat{i < aLen} ->
c: Hacl.Spec.Bignum.Base.carry t
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.limb t | {
"end_col": 54,
"end_line": 51,
"start_col": 32,
"start_line": 51
} |
Prims.Tot | val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in | val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = | false | null | false | generate_elems aLen aLen (bn_add_carry_f a) c_in | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Spec.Lib.generate_elems",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Addition.bn_add_carry_f",
"FStar.Pervasives.Native.tuple2"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen) | [] | Hacl.Spec.Bignum.Addition.bn_add_carry | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> c_in: Hacl.Spec.Bignum.Base.carry t
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t aLen | {
"end_col": 83,
"end_line": 48,
"start_col": 35,
"start_line": 48
} |
Prims.Tot | val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0) | val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = | false | null | false | addcarry c_in a.[ i ] (uint #t 0) | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Spec.Bignum.Base.addcarry",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"FStar.Pervasives.Native.tuple2"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0 | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t | [] | Hacl.Spec.Bignum.Addition.bn_add_carry_f | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
i: Lib.IntTypes.size_nat{i < aLen} ->
c_in: Hacl.Spec.Bignum.Base.carry t
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.limb t | {
"end_col": 70,
"end_line": 45,
"start_col": 39,
"start_line": 45
} |
Prims.Tot | val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in | val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = | false | null | false | generate_elems aLen aLen (bn_sub_carry_f a) c_in | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Spec.Lib.generate_elems",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Addition.bn_sub_carry_f",
"FStar.Pervasives.Native.tuple2"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen) | [] | Hacl.Spec.Bignum.Addition.bn_sub_carry | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> c_in: Hacl.Spec.Bignum.Base.carry t
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t aLen | {
"end_col": 83,
"end_line": 19,
"start_col": 35,
"start_line": 19
} |
Prims.Tot | val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0) | val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = | false | null | false | subborrow c_in a.[ i ] (uint #t 0) | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Spec.Bignum.Base.subborrow",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"FStar.Pervasives.Native.tuple2"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t | [] | Hacl.Spec.Bignum.Addition.bn_sub_carry_f | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
i: Lib.IntTypes.size_nat{i < aLen} ->
c_in: Hacl.Spec.Bignum.Base.carry t
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.limb t | {
"end_col": 71,
"end_line": 16,
"start_col": 39,
"start_line": 16
} |
Prims.Tot | val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0 | val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b = | false | null | false | let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen
then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0 | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Lib.Sequence.seq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.eq2",
"Prims.nat",
"Lib.Sequence.length",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Sequence.concat",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Addition.bn_sub_carry",
"Lib.Sequence.sub",
"Prims.bool",
"Hacl.Spec.Lib.generate_elems",
"Hacl.Spec.Bignum.Addition.bn_sub_f",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i] | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen) | [] | Hacl.Spec.Bignum.Addition.bn_sub | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t aLen | {
"end_col": 15,
"end_line": 31,
"start_col": 31,
"start_line": 25
} |
FStar.Pervasives.Lemma | val bn_sub_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_sub_carry a c_in in
bn_v res - v c_out * pow2 (bits t * aLen) == bn_v a - v c_in) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_sub_carry a c_in in
bn_sub_carry_lemma_loop a c_in aLen | val bn_sub_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_sub_carry a c_in in
bn_v res - v c_out * pow2 (bits t * aLen) == bn_v a - v c_in)
let bn_sub_carry_lemma #t #aLen a c_in = | false | null | true | let c_out, res = bn_sub_carry a c_in in
bn_sub_carry_lemma_loop a c_in aLen | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Spec.Bignum.Addition.bn_sub_carry_lemma_loop",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Addition.bn_sub_carry"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen
val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i))
let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1);
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
let rec bn_add_lemma_loop #t #aLen a b i =
let pbits = bits t in
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_add_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1));
bn_add_lemma_loop a b (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1));
bn_add_lemma_loop_step a b i (c1, res1);
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i);
() end
val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen)))
let bn_add_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_add_carry a1 c0 in
bn_add_carry_lemma a1 c0;
assert (v c1 * pow2 (pbits * (aLen - bLen)) + bn_v res1 == bn_v a1 + v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0 - v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c0) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - v c1 * pow2 (pbits * aLen);
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1) (v c0) }
eval_ bLen a0 bLen + eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 - v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (pbits * aLen);
}
val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_add a b in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b)
let bn_add_lemma #t #aLen #bLen a b =
let pbits = bits t in
let (c, res) = bn_add a b in
if bLen = aLen then
bn_add_lemma_loop a b aLen
else begin
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_add_f a0 b) (uint #t 0) in
bn_add_lemma_loop a0 b bLen;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #bLen res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma #t #aLen #bLen a b c0 res0 end
val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1)
let bn_add1_lemma #t #aLen a b1 =
let pbits = bits t in
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
assert (v c0 * pow2 pbits + v r0 = v a.[0] + v b1);
let res0 = create 1 r0 in
let b = create 1 b1 in
bn_eval1 res0;
bn_eval1 b;
if aLen = 1 then
bn_eval1 a
else begin
let bLen = 1 in
let a0 = sub a 0 bLen in
bn_eval1 a0;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #1 res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma a b c0 res0 end
val bn_sub_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) c1_res1 in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in))
let bn_sub_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let pbits = bits t in
let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_sub_carry_f a (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[i - 1] - v c1);
calc (==) {
bn_v #t #i res - v c * pow2 (pbits * i);
(==) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] - v e + v c * pow2 pbits) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i a i }
eval_ aLen a i - v c_in;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - v c_in)
val bn_sub_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in)
let rec bn_sub_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_sub_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in in
generate_elems_unfold aLen i (bn_sub_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_sub_carry_f a) c_in ==
generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1));
bn_sub_carry_lemma_loop a c_in (i - 1);
assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (pbits * (i - 1)) == eval_ aLen a (i - 1) - v c_in);
bn_sub_carry_lemma_loop_step a c_in i (c1, res1);
assert (bn_v #t #i res - v c_out * pow2 (pbits * i) == eval_ aLen a i - v c_in);
() end
val bn_sub_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_sub_carry a c_in in
bn_v res - v c_out * pow2 (bits t * aLen) == bn_v a - v c_in) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_sub_carry a c_in in
bn_v res - v c_out * pow2 (bits t * aLen) == bn_v a - v c_in) | [] | Hacl.Spec.Bignum.Addition.bn_sub_carry_lemma | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> c_in: Hacl.Spec.Bignum.Base.carry t
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Bignum.Addition.bn_sub_carry a c_in in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c_out res = _ in
Hacl.Spec.Bignum.Definitions.bn_v res -
Lib.IntTypes.v c_out * Prims.pow2 (Lib.IntTypes.bits t * aLen) ==
Hacl.Spec.Bignum.Definitions.bn_v a - Lib.IntTypes.v c_in)
<:
Type0)) | {
"end_col": 37,
"end_line": 399,
"start_col": 40,
"start_line": 397
} |
Prims.Tot | val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0 | val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b = | false | null | false | let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen
then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0 | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Lib.Sequence.seq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.eq2",
"Prims.nat",
"Lib.Sequence.length",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Sequence.concat",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Addition.bn_add_carry",
"Lib.Sequence.sub",
"Prims.bool",
"Hacl.Spec.Lib.generate_elems",
"Hacl.Spec.Bignum.Addition.bn_add_f",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i] | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen | [] | Hacl.Spec.Bignum.Addition.bn_add | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t aLen | {
"end_col": 15,
"end_line": 60,
"start_col": 31,
"start_line": 54
} |
FStar.Pervasives.Lemma | val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen | val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in = | false | null | true | let c_out, res = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Spec.Bignum.Addition.bn_add_carry_lemma_loop",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Addition.bn_add_carry"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in) | [] | Hacl.Spec.Bignum.Addition.bn_add_carry_lemma | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> c_in: Hacl.Spec.Bignum.Base.carry t
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Bignum.Addition.bn_add_carry a c_in in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c_out res = _ in
Lib.IntTypes.v c_out * Prims.pow2 (Lib.IntTypes.bits t * aLen) +
Hacl.Spec.Bignum.Definitions.bn_v res ==
Hacl.Spec.Bignum.Definitions.bn_v a + Lib.IntTypes.v c_in)
<:
Type0)) | {
"end_col": 37,
"end_line": 149,
"start_col": 40,
"start_line": 147
} |
Prims.Tot | val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0 | val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 = | false | null | false | let c0, r0 = subborrow (uint #t 0) a.[ 0 ] b1 in
let res0 = create 1 r0 in
if 1 < aLen
then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0 | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Base.carry",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Sequence.concat",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Addition.bn_sub_carry",
"Lib.Sequence.sub",
"Prims.bool",
"Lib.Sequence.lseq",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Hacl.Spec.Bignum.Base.subborrow",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Lib.Sequence.op_String_Access"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0 | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen) | [] | Hacl.Spec.Bignum.Addition.bn_sub1 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Spec.Bignum.Definitions.limb t
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t aLen | {
"end_col": 15,
"end_line": 41,
"start_col": 27,
"start_line": 34
} |
Prims.Tot | val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0 | val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 = | false | null | false | let c0, r0 = addcarry (uint #t 0) a.[ 0 ] b1 in
let res0 = create 1 r0 in
if 1 < aLen
then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0 | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"total"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Base.carry",
"Prims.op_LessThan",
"Prims.op_Subtraction",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Sequence.concat",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Addition.bn_add_carry",
"Lib.Sequence.sub",
"Prims.bool",
"Lib.Sequence.lseq",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.create",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_imp",
"Prims.b2t",
"Lib.Sequence.index",
"Lib.Sequence.create",
"Hacl.Spec.Bignum.Base.addcarry",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Lib.Sequence.op_String_Access"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0 | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen) | [] | Hacl.Spec.Bignum.Addition.bn_add1 | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Spec.Bignum.Definitions.limb t
-> Hacl.Spec.Bignum.Base.carry t * Hacl.Spec.Bignum.Definitions.lbignum t aLen | {
"end_col": 15,
"end_line": 70,
"start_col": 27,
"start_line": 63
} |
FStar.Pervasives.Lemma | val bn_sub_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_sub a b in
bn_v res - v c * pow2 (bits t * aLen) == bn_v a - bn_v b) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_lemma #t #aLen #bLen a b =
let pbits = bits t in
let (c, res) = bn_sub a b in
if bLen = aLen then
bn_sub_lemma_loop a b aLen
else begin
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_sub_f a0 b) (uint #t 0) in
bn_sub_lemma_loop a0 b bLen;
assert (bn_v #t #bLen res0 - v c0 * pow2 (pbits * bLen) == eval_ bLen a0 bLen - eval_ bLen b bLen);
bn_sub_concat_lemma #t #aLen #bLen a b c0 res0 end | val bn_sub_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_sub a b in
bn_v res - v c * pow2 (bits t * aLen) == bn_v a - bn_v b)
let bn_sub_lemma #t #aLen #bLen a b = | false | null | true | let pbits = bits t in
let c, res = bn_sub a b in
if bLen = aLen
then bn_sub_lemma_loop a b aLen
else
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_sub_f a0 b) (uint #t 0) in
bn_sub_lemma_loop a0 b bLen;
assert (bn_v #t #bLen res0 - v c0 * pow2 (pbits * bLen) == eval_ bLen a0 bLen - eval_ bLen b bLen);
bn_sub_concat_lemma #t #aLen #bLen a b c0 res0 | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.op_Equality",
"Hacl.Spec.Bignum.Addition.bn_sub_lemma_loop",
"Prims.bool",
"Lib.Sequence.seq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.eq2",
"Prims.nat",
"Lib.Sequence.length",
"Hacl.Spec.Bignum.Addition.bn_sub_concat_lemma",
"Prims.unit",
"Prims._assert",
"Prims.int",
"Prims.op_Subtraction",
"Hacl.Spec.Bignum.Definitions.bn_v",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Hacl.Spec.Bignum.Definitions.eval_",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Lib.generate_elems",
"Hacl.Spec.Bignum.Addition.bn_sub_f",
"Lib.IntTypes.uint",
"Lib.Sequence.lseq",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"Prims.l_Forall",
"Prims.op_LessThan",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.Sequence.sub",
"Hacl.Spec.Bignum.Addition.bn_sub",
"Lib.IntTypes.bits"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen
val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i))
let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1);
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
let rec bn_add_lemma_loop #t #aLen a b i =
let pbits = bits t in
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_add_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1));
bn_add_lemma_loop a b (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1));
bn_add_lemma_loop_step a b i (c1, res1);
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i);
() end
val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen)))
let bn_add_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_add_carry a1 c0 in
bn_add_carry_lemma a1 c0;
assert (v c1 * pow2 (pbits * (aLen - bLen)) + bn_v res1 == bn_v a1 + v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0 - v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c0) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - v c1 * pow2 (pbits * aLen);
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1) (v c0) }
eval_ bLen a0 bLen + eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 - v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (pbits * aLen);
}
val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_add a b in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b)
let bn_add_lemma #t #aLen #bLen a b =
let pbits = bits t in
let (c, res) = bn_add a b in
if bLen = aLen then
bn_add_lemma_loop a b aLen
else begin
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_add_f a0 b) (uint #t 0) in
bn_add_lemma_loop a0 b bLen;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #bLen res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma #t #aLen #bLen a b c0 res0 end
val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1)
let bn_add1_lemma #t #aLen a b1 =
let pbits = bits t in
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
assert (v c0 * pow2 pbits + v r0 = v a.[0] + v b1);
let res0 = create 1 r0 in
let b = create 1 b1 in
bn_eval1 res0;
bn_eval1 b;
if aLen = 1 then
bn_eval1 a
else begin
let bLen = 1 in
let a0 = sub a 0 bLen in
bn_eval1 a0;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #1 res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma a b c0 res0 end
val bn_sub_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) c1_res1 in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in))
let bn_sub_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let pbits = bits t in
let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_sub_carry_f a (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[i - 1] - v c1);
calc (==) {
bn_v #t #i res - v c * pow2 (pbits * i);
(==) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] - v e + v c * pow2 pbits) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i a i }
eval_ aLen a i - v c_in;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - v c_in)
val bn_sub_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in)
let rec bn_sub_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_sub_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in in
generate_elems_unfold aLen i (bn_sub_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_sub_carry_f a) c_in ==
generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1));
bn_sub_carry_lemma_loop a c_in (i - 1);
assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (pbits * (i - 1)) == eval_ aLen a (i - 1) - v c_in);
bn_sub_carry_lemma_loop_step a c_in i (c1, res1);
assert (bn_v #t #i res - v c_out * pow2 (pbits * i) == eval_ aLen a i - v c_in);
() end
val bn_sub_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_sub_carry a c_in in
bn_v res - v c_out * pow2 (bits t * aLen) == bn_v a - v c_in)
let bn_sub_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_sub_carry a c_in in
bn_sub_carry_lemma_loop a c_in aLen
val bn_sub_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1)))
(ensures
(let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) c1_res1 in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i))
let bn_sub_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) (c1, res1) in
let c, e = bn_sub_f a b (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[i - 1] - v b.[i - 1] - v c1);
calc (==) {
bn_v #t #i res - v c * pow2 (pbits * i);
(==) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits - v e) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1] - v b.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) - v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i a i }
eval_ aLen a i - eval_ aLen b (i - 1) - v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i b i }
eval_ aLen a i - eval_ aLen b i;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - eval_ aLen b i)
val bn_sub_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_f a b) (uint #t 0) in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i)
let rec bn_sub_lemma_loop #t #aLen a b i =
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_sub_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_sub_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_sub_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_sub_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_sub_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_sub_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_sub_f a b) (i - 1) (c1, res1));
bn_sub_lemma_loop a b (i - 1);
assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1));
bn_sub_lemma_loop_step a b i (c1, res1);
assert (bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i);
() end
val bn_sub_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
bn_v #t #bLen res0 - v c0 * pow2 (bits t * bLen) == eval_ bLen (sub a 0 bLen) bLen - eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen - eval_ bLen b bLen + v c1 * pow2 (bits t * aLen)))
let bn_sub_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_sub_carry a1 c0 in
bn_sub_carry_lemma a1 c0;
assert (bn_v res1 - v c1 * pow2 (pbits * (aLen - bLen)) == bn_v a1 - v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen - eval_ bLen b bLen + v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 - v c0 + v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c1 * pow2 (pbits * (aLen - bLen))) (v c0) }
eval_ bLen a0 bLen - eval_ bLen b bLen + v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c1 * pow2 (pbits * (aLen - bLen))) - pow2 (pbits * bLen) * v c0;
(==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * bLen)) (bn_v a1) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen - eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 + pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen - eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 + v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen - eval_ bLen b bLen + v c1 * pow2 (pbits * aLen);
}
val bn_sub_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_sub a b in
bn_v res - v c * pow2 (bits t * aLen) == bn_v a - bn_v b) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_sub a b in
bn_v res - v c * pow2 (bits t * aLen) == bn_v a - bn_v b) | [] | Hacl.Spec.Bignum.Addition.bn_sub_lemma | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Bignum.Addition.bn_sub a b in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
Hacl.Spec.Bignum.Definitions.bn_v res -
Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * aLen) ==
Hacl.Spec.Bignum.Definitions.bn_v a - Hacl.Spec.Bignum.Definitions.bn_v b)
<:
Type0)) | {
"end_col": 54,
"end_line": 539,
"start_col": 37,
"start_line": 527
} |
FStar.Pervasives.Lemma | val bn_sub1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_sub1 a b1 in
bn_v res - v c * pow2 (bits t * aLen) == bn_v a - v b1) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub1_lemma #t #aLen a b1 =
let pbits = bits t in
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
assert (v r0 - v c0 * pow2 pbits = v a.[0] - v b1);
let res0 = create 1 r0 in
let b = create 1 b1 in
bn_eval1 res0;
bn_eval1 b;
if aLen = 1 then
bn_eval1 a
else begin
let bLen = 1 in
let a0 = sub a 0 bLen in
bn_eval1 a0;
assert (bn_v #t #1 res0 - v c0 * pow2 (pbits * bLen) == eval_ bLen a0 bLen - eval_ bLen b bLen);
bn_sub_concat_lemma a b c0 res0 end | val bn_sub1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_sub1 a b1 in
bn_v res - v c * pow2 (bits t * aLen) == bn_v a - v b1)
let bn_sub1_lemma #t #aLen a b1 = | false | null | true | let pbits = bits t in
let c0, r0 = subborrow (uint #t 0) a.[ 0 ] b1 in
assert (v r0 - v c0 * pow2 pbits = v a.[ 0 ] - v b1);
let res0 = create 1 r0 in
let b = create 1 b1 in
bn_eval1 res0;
bn_eval1 b;
if aLen = 1
then bn_eval1 a
else
let bLen = 1 in
let a0 = sub a 0 bLen in
bn_eval1 a0;
assert (bn_v #t #1 res0 - v c0 * pow2 (pbits * bLen) == eval_ bLen a0 bLen - eval_ bLen b bLen);
bn_sub_concat_lemma a b c0 res0 | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Base.carry",
"Prims.op_Equality",
"Prims.int",
"Hacl.Spec.Bignum.Definitions.bn_eval1",
"Prims.bool",
"Hacl.Spec.Bignum.Addition.bn_sub_concat_lemma",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.op_Subtraction",
"Hacl.Spec.Bignum.Definitions.bn_v",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Hacl.Spec.Bignum.Definitions.eval_",
"Lib.Sequence.lseq",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.Sequence.sub",
"FStar.Seq.Base.create",
"Prims.l_imp",
"Lib.Sequence.create",
"Lib.Sequence.op_String_Access",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Base.subborrow",
"Lib.IntTypes.uint",
"Lib.IntTypes.bits"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen
val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i))
let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1);
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
let rec bn_add_lemma_loop #t #aLen a b i =
let pbits = bits t in
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_add_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1));
bn_add_lemma_loop a b (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1));
bn_add_lemma_loop_step a b i (c1, res1);
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i);
() end
val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen)))
let bn_add_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_add_carry a1 c0 in
bn_add_carry_lemma a1 c0;
assert (v c1 * pow2 (pbits * (aLen - bLen)) + bn_v res1 == bn_v a1 + v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0 - v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c0) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - v c1 * pow2 (pbits * aLen);
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1) (v c0) }
eval_ bLen a0 bLen + eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 - v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (pbits * aLen);
}
val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_add a b in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b)
let bn_add_lemma #t #aLen #bLen a b =
let pbits = bits t in
let (c, res) = bn_add a b in
if bLen = aLen then
bn_add_lemma_loop a b aLen
else begin
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_add_f a0 b) (uint #t 0) in
bn_add_lemma_loop a0 b bLen;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #bLen res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma #t #aLen #bLen a b c0 res0 end
val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1)
let bn_add1_lemma #t #aLen a b1 =
let pbits = bits t in
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
assert (v c0 * pow2 pbits + v r0 = v a.[0] + v b1);
let res0 = create 1 r0 in
let b = create 1 b1 in
bn_eval1 res0;
bn_eval1 b;
if aLen = 1 then
bn_eval1 a
else begin
let bLen = 1 in
let a0 = sub a 0 bLen in
bn_eval1 a0;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #1 res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma a b c0 res0 end
val bn_sub_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) c1_res1 in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in))
let bn_sub_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let pbits = bits t in
let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_sub_carry_f a (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[i - 1] - v c1);
calc (==) {
bn_v #t #i res - v c * pow2 (pbits * i);
(==) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] - v e + v c * pow2 pbits) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i a i }
eval_ aLen a i - v c_in;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - v c_in)
val bn_sub_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in)
let rec bn_sub_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_sub_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in in
generate_elems_unfold aLen i (bn_sub_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_sub_carry_f a) c_in ==
generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1));
bn_sub_carry_lemma_loop a c_in (i - 1);
assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (pbits * (i - 1)) == eval_ aLen a (i - 1) - v c_in);
bn_sub_carry_lemma_loop_step a c_in i (c1, res1);
assert (bn_v #t #i res - v c_out * pow2 (pbits * i) == eval_ aLen a i - v c_in);
() end
val bn_sub_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_sub_carry a c_in in
bn_v res - v c_out * pow2 (bits t * aLen) == bn_v a - v c_in)
let bn_sub_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_sub_carry a c_in in
bn_sub_carry_lemma_loop a c_in aLen
val bn_sub_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1)))
(ensures
(let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) c1_res1 in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i))
let bn_sub_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) (c1, res1) in
let c, e = bn_sub_f a b (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[i - 1] - v b.[i - 1] - v c1);
calc (==) {
bn_v #t #i res - v c * pow2 (pbits * i);
(==) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits - v e) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1] - v b.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) - v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i a i }
eval_ aLen a i - eval_ aLen b (i - 1) - v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i b i }
eval_ aLen a i - eval_ aLen b i;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - eval_ aLen b i)
val bn_sub_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_f a b) (uint #t 0) in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i)
let rec bn_sub_lemma_loop #t #aLen a b i =
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_sub_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_sub_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_sub_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_sub_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_sub_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_sub_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_sub_f a b) (i - 1) (c1, res1));
bn_sub_lemma_loop a b (i - 1);
assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1));
bn_sub_lemma_loop_step a b i (c1, res1);
assert (bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i);
() end
val bn_sub_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
bn_v #t #bLen res0 - v c0 * pow2 (bits t * bLen) == eval_ bLen (sub a 0 bLen) bLen - eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen - eval_ bLen b bLen + v c1 * pow2 (bits t * aLen)))
let bn_sub_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_sub_carry a1 c0 in
bn_sub_carry_lemma a1 c0;
assert (bn_v res1 - v c1 * pow2 (pbits * (aLen - bLen)) == bn_v a1 - v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen - eval_ bLen b bLen + v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 - v c0 + v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c1 * pow2 (pbits * (aLen - bLen))) (v c0) }
eval_ bLen a0 bLen - eval_ bLen b bLen + v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c1 * pow2 (pbits * (aLen - bLen))) - pow2 (pbits * bLen) * v c0;
(==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * bLen)) (bn_v a1) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen - eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 + pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen - eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 + v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen - eval_ bLen b bLen + v c1 * pow2 (pbits * aLen);
}
val bn_sub_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_sub a b in
bn_v res - v c * pow2 (bits t * aLen) == bn_v a - bn_v b)
let bn_sub_lemma #t #aLen #bLen a b =
let pbits = bits t in
let (c, res) = bn_sub a b in
if bLen = aLen then
bn_sub_lemma_loop a b aLen
else begin
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_sub_f a0 b) (uint #t 0) in
bn_sub_lemma_loop a0 b bLen;
assert (bn_v #t #bLen res0 - v c0 * pow2 (pbits * bLen) == eval_ bLen a0 bLen - eval_ bLen b bLen);
bn_sub_concat_lemma #t #aLen #bLen a b c0 res0 end
val bn_sub1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_sub1 a b1 in
bn_v res - v c * pow2 (bits t * aLen) == bn_v a - v b1) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_sub1 a b1 in
bn_v res - v c * pow2 (bits t * aLen) == bn_v a - v b1) | [] | Hacl.Spec.Bignum.Addition.bn_sub1_lemma | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Spec.Bignum.Definitions.limb t
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Bignum.Addition.bn_sub1 a b1 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
Hacl.Spec.Bignum.Definitions.bn_v res -
Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * aLen) ==
Hacl.Spec.Bignum.Definitions.bn_v a - Lib.IntTypes.v b1)
<:
Type0)) | {
"end_col": 39,
"end_line": 567,
"start_col": 33,
"start_line": 550
} |
FStar.Pervasives.Lemma | val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add1_lemma #t #aLen a b1 =
let pbits = bits t in
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
assert (v c0 * pow2 pbits + v r0 = v a.[0] + v b1);
let res0 = create 1 r0 in
let b = create 1 b1 in
bn_eval1 res0;
bn_eval1 b;
if aLen = 1 then
bn_eval1 a
else begin
let bLen = 1 in
let a0 = sub a 0 bLen in
bn_eval1 a0;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #1 res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma a b c0 res0 end | val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1)
let bn_add1_lemma #t #aLen a b1 = | false | null | true | let pbits = bits t in
let c0, r0 = addcarry (uint #t 0) a.[ 0 ] b1 in
assert (v c0 * pow2 pbits + v r0 = v a.[ 0 ] + v b1);
let res0 = create 1 r0 in
let b = create 1 b1 in
bn_eval1 res0;
bn_eval1 b;
if aLen = 1
then bn_eval1 a
else
let bLen = 1 in
let a0 = sub a 0 bLen in
bn_eval1 a0;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #1 res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma a b c0 res0 | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_pos",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Base.carry",
"Prims.op_Equality",
"Prims.int",
"Hacl.Spec.Bignum.Definitions.bn_eval1",
"Prims.bool",
"Hacl.Spec.Bignum.Addition.bn_add_concat_lemma",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.Definitions.eval_",
"Lib.Sequence.lseq",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.l_Forall",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.Sequence.sub",
"FStar.Seq.Base.create",
"Prims.l_imp",
"Lib.Sequence.create",
"Lib.Sequence.op_String_Access",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Base.addcarry",
"Lib.IntTypes.uint",
"Lib.IntTypes.bits"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen
val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i))
let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1);
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
let rec bn_add_lemma_loop #t #aLen a b i =
let pbits = bits t in
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_add_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1));
bn_add_lemma_loop a b (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1));
bn_add_lemma_loop_step a b i (c1, res1);
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i);
() end
val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen)))
let bn_add_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_add_carry a1 c0 in
bn_add_carry_lemma a1 c0;
assert (v c1 * pow2 (pbits * (aLen - bLen)) + bn_v res1 == bn_v a1 + v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0 - v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c0) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - v c1 * pow2 (pbits * aLen);
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1) (v c0) }
eval_ bLen a0 bLen + eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 - v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (pbits * aLen);
}
val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_add a b in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b)
let bn_add_lemma #t #aLen #bLen a b =
let pbits = bits t in
let (c, res) = bn_add a b in
if bLen = aLen then
bn_add_lemma_loop a b aLen
else begin
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_add_f a0 b) (uint #t 0) in
bn_add_lemma_loop a0 b bLen;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #bLen res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma #t #aLen #bLen a b c0 res0 end
val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1) | [] | Hacl.Spec.Bignum.Addition.bn_add1_lemma | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b1: Hacl.Spec.Bignum.Definitions.limb t
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Bignum.Addition.bn_add1 a b1 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * aLen) +
Hacl.Spec.Bignum.Definitions.bn_v res ==
Hacl.Spec.Bignum.Definitions.bn_v a + Lib.IntTypes.v b1)
<:
Type0)) | {
"end_col": 39,
"end_line": 319,
"start_col": 33,
"start_line": 302
} |
FStar.Pervasives.Lemma | val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_add a b in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_lemma #t #aLen #bLen a b =
let pbits = bits t in
let (c, res) = bn_add a b in
if bLen = aLen then
bn_add_lemma_loop a b aLen
else begin
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_add_f a0 b) (uint #t 0) in
bn_add_lemma_loop a0 b bLen;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #bLen res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma #t #aLen #bLen a b c0 res0 end | val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_add a b in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b)
let bn_add_lemma #t #aLen #bLen a b = | false | null | true | let pbits = bits t in
let c, res = bn_add a b in
if bLen = aLen
then bn_add_lemma_loop a b aLen
else
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_add_f a0 b) (uint #t 0) in
bn_add_lemma_loop a0 b bLen;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #bLen res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma #t #aLen #bLen a b c0 res0 | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.op_Equality",
"Hacl.Spec.Bignum.Addition.bn_add_lemma_loop",
"Prims.bool",
"Lib.Sequence.seq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.eq2",
"Prims.nat",
"Lib.Sequence.length",
"Hacl.Spec.Bignum.Addition.bn_add_concat_lemma",
"Prims.unit",
"Prims._assert",
"Prims.int",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.Definitions.eval_",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Lib.generate_elems",
"Hacl.Spec.Bignum.Addition.bn_add_f",
"Lib.IntTypes.uint",
"Lib.Sequence.lseq",
"Prims.op_Subtraction",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.slice",
"Prims.l_Forall",
"Prims.op_LessThan",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.Sequence.sub",
"Hacl.Spec.Bignum.Addition.bn_add",
"Lib.IntTypes.bits"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen
val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i))
let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1);
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
let rec bn_add_lemma_loop #t #aLen a b i =
let pbits = bits t in
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_add_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1));
bn_add_lemma_loop a b (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1));
bn_add_lemma_loop_step a b i (c1, res1);
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i);
() end
val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen)))
let bn_add_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_add_carry a1 c0 in
bn_add_carry_lemma a1 c0;
assert (v c1 * pow2 (pbits * (aLen - bLen)) + bn_v res1 == bn_v a1 + v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0 - v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c0) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - v c1 * pow2 (pbits * aLen);
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1) (v c0) }
eval_ bLen a0 bLen + eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 - v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (pbits * aLen);
}
val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_add a b in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_add a b in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b) | [] | Hacl.Spec.Bignum.Addition.bn_add_lemma | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | a: Hacl.Spec.Bignum.Definitions.lbignum t aLen -> b: Hacl.Spec.Bignum.Definitions.lbignum t bLen
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Bignum.Addition.bn_add a b in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * aLen) +
Hacl.Spec.Bignum.Definitions.bn_v res ==
Hacl.Spec.Bignum.Definitions.bn_v a + Hacl.Spec.Bignum.Definitions.bn_v b)
<:
Type0)) | {
"end_col": 54,
"end_line": 291,
"start_col": 37,
"start_line": 279
} |
FStar.Pervasives.Lemma | val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec bn_add_lemma_loop #t #aLen a b i =
let pbits = bits t in
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_add_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1));
bn_add_lemma_loop a b (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1));
bn_add_lemma_loop_step a b i (c1, res1);
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i);
() end | val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
let rec bn_add_lemma_loop #t #aLen a b i = | false | null | true | let pbits = bits t in
let c, res:generate_elem_a (limb t) (carry t) aLen i =
generate_elems aLen i (bn_add_f a b) (uint #t 0)
in
if i = 0
then
(eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
())
else
let c1, res1:generate_elem_a (limb t) (carry t) aLen (i - 1) =
generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)
in
generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) ==
generate_elem_f aLen
(bn_add_f a b)
(i - 1)
(generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1));
bn_add_lemma_loop a b (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 ==
eval_ aLen a (i - 1) + eval_ aLen b (i - 1));
bn_add_lemma_loop_step a b i (c1, res1);
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i);
() | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Bignum.Base.carry",
"Lib.Sequence.seq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.eq2",
"Lib.Sequence.length",
"Prims.op_Equality",
"Prims.int",
"Prims.unit",
"Hacl.Spec.Bignum.Definitions.bn_eval0",
"FStar.Pervasives.assert_norm",
"Prims.pow2",
"Prims._assert",
"Prims.l_and",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Prims.l_or",
"Lib.IntTypes.uint_v",
"Lib.IntTypes.range",
"Lib.IntTypes.v",
"Lib.IntTypes.uint",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.length",
"FStar.Seq.Base.empty",
"Hacl.Spec.Lib.eq_generate_elems0",
"Hacl.Spec.Bignum.Addition.bn_add_f",
"Prims.bool",
"Prims.op_Subtraction",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.Definitions.eval_",
"Hacl.Spec.Bignum.Addition.bn_add_lemma_loop_step",
"FStar.Pervasives.Native.Mktuple2",
"Hacl.Spec.Bignum.Addition.bn_add_lemma_loop",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Lib.generate_elem_f",
"Hacl.Spec.Lib.generate_elems",
"Hacl.Spec.Lib.generate_elems_unfold",
"Hacl.Spec.Lib.generate_elem_a",
"Lib.IntTypes.bits"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen
val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i))
let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1);
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i) | [
"recursion"
] | Hacl.Spec.Bignum.Addition.bn_add_lemma_loop | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
b: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
i: Prims.nat{i <= aLen}
-> FStar.Pervasives.Lemma
(ensures
(let _ =
Hacl.Spec.Lib.generate_elems aLen
i
(Hacl.Spec.Bignum.Addition.bn_add_f a b)
(Lib.IntTypes.uint 0)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
let _ = _ in
Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * i) +
Hacl.Spec.Bignum.Definitions.bn_v res ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a i + Hacl.Spec.Bignum.Definitions.eval_ aLen b i)
<:
Type0)) | {
"end_col": 10,
"end_line": 225,
"start_col": 42,
"start_line": 204
} |
FStar.Pervasives.Lemma | val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end | val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i = | false | null | true | let pbits = bits t in
let c_out, res:generate_elem_a (limb t) (carry t) aLen i =
generate_elems aLen i (bn_add_carry_f a) c_in
in
if i = 0
then
(eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
())
else
let c1, res1:generate_elem_a (limb t) (carry t) aLen (i - 1) =
generate_elems aLen (i - 1) (bn_add_carry_f a) c_in
in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen
(bn_add_carry_f a)
(i - 1)
(generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.Sequence.seq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.eq2",
"Lib.Sequence.length",
"Prims.op_Equality",
"Prims.int",
"Prims.unit",
"Hacl.Spec.Bignum.Definitions.bn_eval0",
"FStar.Pervasives.assert_norm",
"Prims.pow2",
"Prims._assert",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Prims.l_or",
"FStar.Seq.Base.length",
"FStar.Seq.Base.empty",
"Hacl.Spec.Lib.eq_generate_elems0",
"Hacl.Spec.Bignum.Addition.bn_add_carry_f",
"Prims.bool",
"Prims.op_Subtraction",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.Definitions.eval_",
"Hacl.Spec.Bignum.Addition.bn_add_carry_lemma_loop_step",
"FStar.Pervasives.Native.Mktuple2",
"Hacl.Spec.Bignum.Addition.bn_add_carry_lemma_loop",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Lib.generate_elem_f",
"Hacl.Spec.Lib.generate_elems",
"Hacl.Spec.Lib.generate_elems_unfold",
"Hacl.Spec.Lib.generate_elem_a",
"Lib.IntTypes.bits"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in) | [
"recursion"
] | Hacl.Spec.Bignum.Addition.bn_add_carry_lemma_loop | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
c_in: Hacl.Spec.Bignum.Base.carry t ->
i: Prims.nat{i <= aLen}
-> FStar.Pervasives.Lemma
(ensures
(let _ =
Hacl.Spec.Lib.generate_elems aLen i (Hacl.Spec.Bignum.Addition.bn_add_carry_f a) c_in
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c_out res = _ in
let _ = _ in
Lib.IntTypes.v c_out * Prims.pow2 (Lib.IntTypes.bits t * i) +
Hacl.Spec.Bignum.Definitions.bn_v res ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a i + Lib.IntTypes.v c_in)
<:
Type0)) | {
"end_col": 10,
"end_line": 140,
"start_col": 51,
"start_line": 120
} |
FStar.Pervasives.Lemma | val bn_sub_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec bn_sub_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_sub_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in in
generate_elems_unfold aLen i (bn_sub_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_sub_carry_f a) c_in ==
generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1));
bn_sub_carry_lemma_loop a c_in (i - 1);
assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (pbits * (i - 1)) == eval_ aLen a (i - 1) - v c_in);
bn_sub_carry_lemma_loop_step a c_in i (c1, res1);
assert (bn_v #t #i res - v c_out * pow2 (pbits * i) == eval_ aLen a i - v c_in);
() end | val bn_sub_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in)
let rec bn_sub_carry_lemma_loop #t #aLen a c_in i = | false | null | true | let pbits = bits t in
let c_out, res:generate_elem_a (limb t) (carry t) aLen i =
generate_elems aLen i (bn_sub_carry_f a) c_in
in
if i = 0
then
(eq_generate_elems0 aLen i (bn_sub_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
())
else
let c1, res1:generate_elem_a (limb t) (carry t) aLen (i - 1) =
generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in
in
generate_elems_unfold aLen i (bn_sub_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_sub_carry_f a) c_in ==
generate_elem_f aLen
(bn_sub_carry_f a)
(i - 1)
(generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1));
bn_sub_carry_lemma_loop a c_in (i - 1);
assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (pbits * (i - 1)) == eval_ aLen a (i - 1) - v c_in);
bn_sub_carry_lemma_loop_step a c_in i (c1, res1);
assert (bn_v #t #i res - v c_out * pow2 (pbits * i) == eval_ aLen a i - v c_in);
() | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Lib.Sequence.seq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.eq2",
"Lib.Sequence.length",
"Prims.op_Equality",
"Prims.int",
"Prims.unit",
"Hacl.Spec.Bignum.Definitions.bn_eval0",
"FStar.Pervasives.assert_norm",
"Prims.pow2",
"Prims._assert",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Prims.l_or",
"FStar.Seq.Base.length",
"FStar.Seq.Base.empty",
"Hacl.Spec.Lib.eq_generate_elems0",
"Hacl.Spec.Bignum.Addition.bn_sub_carry_f",
"Prims.bool",
"Prims.op_Subtraction",
"Hacl.Spec.Bignum.Definitions.bn_v",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Hacl.Spec.Bignum.Definitions.eval_",
"Hacl.Spec.Bignum.Addition.bn_sub_carry_lemma_loop_step",
"FStar.Pervasives.Native.Mktuple2",
"Hacl.Spec.Bignum.Addition.bn_sub_carry_lemma_loop",
"FStar.Pervasives.Native.tuple2",
"Prims.op_Addition",
"Hacl.Spec.Lib.generate_elem_f",
"Hacl.Spec.Lib.generate_elems",
"Hacl.Spec.Lib.generate_elems_unfold",
"Hacl.Spec.Lib.generate_elem_a",
"Lib.IntTypes.bits"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen
val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i))
let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1);
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
let rec bn_add_lemma_loop #t #aLen a b i =
let pbits = bits t in
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_add_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1));
bn_add_lemma_loop a b (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1));
bn_add_lemma_loop_step a b i (c1, res1);
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i);
() end
val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen)))
let bn_add_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_add_carry a1 c0 in
bn_add_carry_lemma a1 c0;
assert (v c1 * pow2 (pbits * (aLen - bLen)) + bn_v res1 == bn_v a1 + v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0 - v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c0) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - v c1 * pow2 (pbits * aLen);
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1) (v c0) }
eval_ bLen a0 bLen + eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 - v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (pbits * aLen);
}
val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_add a b in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b)
let bn_add_lemma #t #aLen #bLen a b =
let pbits = bits t in
let (c, res) = bn_add a b in
if bLen = aLen then
bn_add_lemma_loop a b aLen
else begin
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_add_f a0 b) (uint #t 0) in
bn_add_lemma_loop a0 b bLen;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #bLen res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma #t #aLen #bLen a b c0 res0 end
val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1)
let bn_add1_lemma #t #aLen a b1 =
let pbits = bits t in
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
assert (v c0 * pow2 pbits + v r0 = v a.[0] + v b1);
let res0 = create 1 r0 in
let b = create 1 b1 in
bn_eval1 res0;
bn_eval1 b;
if aLen = 1 then
bn_eval1 a
else begin
let bLen = 1 in
let a0 = sub a 0 bLen in
bn_eval1 a0;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #1 res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma a b c0 res0 end
val bn_sub_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) c1_res1 in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in))
let bn_sub_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let pbits = bits t in
let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_sub_carry_f a (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[i - 1] - v c1);
calc (==) {
bn_v #t #i res - v c * pow2 (pbits * i);
(==) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] - v e + v c * pow2 pbits) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i a i }
eval_ aLen a i - v c_in;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - v c_in)
val bn_sub_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in) | [
"recursion"
] | Hacl.Spec.Bignum.Addition.bn_sub_carry_lemma_loop | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
c_in: Hacl.Spec.Bignum.Base.carry t ->
i: Prims.nat{i <= aLen}
-> FStar.Pervasives.Lemma
(ensures
(let _ =
Hacl.Spec.Lib.generate_elems aLen i (Hacl.Spec.Bignum.Addition.bn_sub_carry_f a) c_in
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c_out res = _ in
let _ = _ in
Hacl.Spec.Bignum.Definitions.bn_v res -
Lib.IntTypes.v c_out * Prims.pow2 (Lib.IntTypes.bits t * i) ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a i - Lib.IntTypes.v c_in)
<:
Type0)) | {
"end_col": 10,
"end_line": 390,
"start_col": 51,
"start_line": 370
} |
FStar.Pervasives.Lemma | val bn_sub_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_f a b) (uint #t 0) in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rec bn_sub_lemma_loop #t #aLen a b i =
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_sub_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_sub_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_sub_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_sub_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_sub_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_sub_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_sub_f a b) (i - 1) (c1, res1));
bn_sub_lemma_loop a b (i - 1);
assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1));
bn_sub_lemma_loop_step a b i (c1, res1);
assert (bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i);
() end | val bn_sub_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_f a b) (uint #t 0) in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i)
let rec bn_sub_lemma_loop #t #aLen a b i = | false | null | true | let c, res:generate_elem_a (limb t) (carry t) aLen i =
generate_elems aLen i (bn_sub_f a b) (uint #t 0)
in
if i = 0
then
(eq_generate_elems0 aLen i (bn_sub_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
())
else
let c1, res1:generate_elem_a (limb t) (carry t) aLen (i - 1) =
generate_elems aLen (i - 1) (bn_sub_f a b) (uint #t 0)
in
generate_elems_unfold aLen i (bn_sub_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_sub_f a b) (uint #t 0) ==
generate_elem_f aLen
(bn_sub_f a b)
(i - 1)
(generate_elems aLen (i - 1) (bn_sub_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_sub_f a b) (i - 1) (c1, res1));
bn_sub_lemma_loop a b (i - 1);
assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) ==
eval_ aLen a (i - 1) - eval_ aLen b (i - 1));
bn_sub_lemma_loop_step a b i (c1, res1);
assert (bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i);
() | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Bignum.Base.carry",
"Lib.Sequence.seq",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.eq2",
"Lib.Sequence.length",
"Prims.op_Equality",
"Prims.int",
"Prims.unit",
"Hacl.Spec.Bignum.Definitions.bn_eval0",
"FStar.Pervasives.assert_norm",
"Prims.pow2",
"Prims._assert",
"Prims.l_and",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Prims.l_or",
"Lib.IntTypes.uint_v",
"Lib.IntTypes.range",
"Lib.IntTypes.v",
"Lib.IntTypes.uint",
"FStar.Seq.Base.seq",
"FStar.Seq.Base.length",
"FStar.Seq.Base.empty",
"Hacl.Spec.Lib.eq_generate_elems0",
"Hacl.Spec.Bignum.Addition.bn_sub_f",
"Prims.bool",
"Prims.op_Subtraction",
"Hacl.Spec.Bignum.Definitions.bn_v",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Hacl.Spec.Bignum.Definitions.eval_",
"Hacl.Spec.Bignum.Addition.bn_sub_lemma_loop_step",
"FStar.Pervasives.Native.Mktuple2",
"Hacl.Spec.Bignum.Addition.bn_sub_lemma_loop",
"FStar.Pervasives.Native.tuple2",
"Prims.op_Addition",
"Hacl.Spec.Lib.generate_elem_f",
"Hacl.Spec.Lib.generate_elems",
"Hacl.Spec.Lib.generate_elems_unfold",
"Hacl.Spec.Lib.generate_elem_a"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen
val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i))
let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1);
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
let rec bn_add_lemma_loop #t #aLen a b i =
let pbits = bits t in
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_add_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1));
bn_add_lemma_loop a b (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1));
bn_add_lemma_loop_step a b i (c1, res1);
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i);
() end
val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen)))
let bn_add_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_add_carry a1 c0 in
bn_add_carry_lemma a1 c0;
assert (v c1 * pow2 (pbits * (aLen - bLen)) + bn_v res1 == bn_v a1 + v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0 - v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c0) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - v c1 * pow2 (pbits * aLen);
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1) (v c0) }
eval_ bLen a0 bLen + eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 - v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (pbits * aLen);
}
val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_add a b in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b)
let bn_add_lemma #t #aLen #bLen a b =
let pbits = bits t in
let (c, res) = bn_add a b in
if bLen = aLen then
bn_add_lemma_loop a b aLen
else begin
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_add_f a0 b) (uint #t 0) in
bn_add_lemma_loop a0 b bLen;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #bLen res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma #t #aLen #bLen a b c0 res0 end
val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1)
let bn_add1_lemma #t #aLen a b1 =
let pbits = bits t in
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
assert (v c0 * pow2 pbits + v r0 = v a.[0] + v b1);
let res0 = create 1 r0 in
let b = create 1 b1 in
bn_eval1 res0;
bn_eval1 b;
if aLen = 1 then
bn_eval1 a
else begin
let bLen = 1 in
let a0 = sub a 0 bLen in
bn_eval1 a0;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #1 res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma a b c0 res0 end
val bn_sub_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) c1_res1 in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in))
let bn_sub_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let pbits = bits t in
let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_sub_carry_f a (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[i - 1] - v c1);
calc (==) {
bn_v #t #i res - v c * pow2 (pbits * i);
(==) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] - v e + v c * pow2 pbits) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i a i }
eval_ aLen a i - v c_in;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - v c_in)
val bn_sub_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in)
let rec bn_sub_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_sub_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in in
generate_elems_unfold aLen i (bn_sub_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_sub_carry_f a) c_in ==
generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1));
bn_sub_carry_lemma_loop a c_in (i - 1);
assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (pbits * (i - 1)) == eval_ aLen a (i - 1) - v c_in);
bn_sub_carry_lemma_loop_step a c_in i (c1, res1);
assert (bn_v #t #i res - v c_out * pow2 (pbits * i) == eval_ aLen a i - v c_in);
() end
val bn_sub_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_sub_carry a c_in in
bn_v res - v c_out * pow2 (bits t * aLen) == bn_v a - v c_in)
let bn_sub_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_sub_carry a c_in in
bn_sub_carry_lemma_loop a c_in aLen
val bn_sub_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1)))
(ensures
(let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) c1_res1 in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i))
let bn_sub_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) (c1, res1) in
let c, e = bn_sub_f a b (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[i - 1] - v b.[i - 1] - v c1);
calc (==) {
bn_v #t #i res - v c * pow2 (pbits * i);
(==) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits - v e) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1] - v b.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) - v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i a i }
eval_ aLen a i - eval_ aLen b (i - 1) - v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i b i }
eval_ aLen a i - eval_ aLen b i;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - eval_ aLen b i)
val bn_sub_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_f a b) (uint #t 0) in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_f a b) (uint #t 0) in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i) | [
"recursion"
] | Hacl.Spec.Bignum.Addition.bn_sub_lemma_loop | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
b: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
i: Prims.nat{i <= aLen}
-> FStar.Pervasives.Lemma
(ensures
(let _ =
Hacl.Spec.Lib.generate_elems aLen
i
(Hacl.Spec.Bignum.Addition.bn_sub_f a b)
(Lib.IntTypes.uint 0)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
let _ = _ in
Hacl.Spec.Bignum.Definitions.bn_v res -
Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * i) ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a i - Hacl.Spec.Bignum.Definitions.eval_ aLen b i)
<:
Type0)) | {
"end_col": 10,
"end_line": 473,
"start_col": 42,
"start_line": 453
} |
FStar.Pervasives.Lemma | val bn_sub_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
bn_v #t #bLen res0 - v c0 * pow2 (bits t * bLen) == eval_ bLen (sub a 0 bLen) bLen - eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen - eval_ bLen b bLen + v c1 * pow2 (bits t * aLen))) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_sub_carry a1 c0 in
bn_sub_carry_lemma a1 c0;
assert (bn_v res1 - v c1 * pow2 (pbits * (aLen - bLen)) == bn_v a1 - v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen - eval_ bLen b bLen + v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 - v c0 + v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c1 * pow2 (pbits * (aLen - bLen))) (v c0) }
eval_ bLen a0 bLen - eval_ bLen b bLen + v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c1 * pow2 (pbits * (aLen - bLen))) - pow2 (pbits * bLen) * v c0;
(==) { Math.Lemmas.distributivity_add_right (pow2 (pbits * bLen)) (bn_v a1) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen - eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 + pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen - eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 + v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen - eval_ bLen b bLen + v c1 * pow2 (pbits * aLen);
} | val bn_sub_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
bn_v #t #bLen res0 - v c0 * pow2 (bits t * bLen) == eval_ bLen (sub a 0 bLen) bLen - eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen - eval_ bLen b bLen + v c1 * pow2 (bits t * aLen)))
let bn_sub_concat_lemma #t #aLen #bLen a b c0 res0 = | false | null | true | let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_sub_carry a1 c0 in
bn_sub_carry_lemma a1 c0;
assert (bn_v res1 - v c1 * pow2 (pbits * (aLen - bLen)) == bn_v a1 - v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc ( == ) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
( == ) { () }
eval_ bLen a0 bLen - eval_ bLen b bLen + v c0 * pow2 (pbits * bLen) +
pow2 (pbits * bLen) * (bn_v a1 - v c0 + v c1 * pow2 (pbits * (aLen - bLen)));
( == ) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen))
(bn_v a1 + v c1 * pow2 (pbits * (aLen - bLen)))
(v c0) }
eval_ bLen a0 bLen - eval_ bLen b bLen + v c0 * pow2 (pbits * bLen) +
pow2 (pbits * bLen) * (bn_v a1 + v c1 * pow2 (pbits * (aLen - bLen))) -
pow2 (pbits * bLen) * v c0;
( == ) { Math.Lemmas.distributivity_add_right (pow2 (pbits * bLen))
(bn_v a1)
(v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen - eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 +
(pow2 (pbits * bLen) * v c1) * pow2 (pbits * (aLen - bLen));
( == ) { (Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen)));
Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen - eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 +
v c1 * pow2 (pbits * aLen);
( == ) { (bn_eval_split_i a bLen;
bn_eval_extensionality_j a (sub a 0 bLen) bLen) }
eval_ aLen a aLen - eval_ bLen b bLen + v c1 * pow2 (pbits * aLen);
} | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.op_Subtraction",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"Hacl.Spec.Bignum.Definitions.bn_v",
"FStar.Mul.op_Star",
"Prims.pow2",
"Hacl.Spec.Bignum.Definitions.eval_",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.distributivity_sub_right",
"FStar.Math.Lemmas.distributivity_add_right",
"FStar.Math.Lemmas.pow2_plus",
"FStar.Math.Lemmas.paren_mul_right",
"Hacl.Spec.Bignum.Definitions.bn_eval_extensionality_j",
"Lib.Sequence.sub",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Definitions.bn_eval_split_i",
"Prims._assert",
"Hacl.Spec.Bignum.Definitions.bn_concat_lemma",
"Lib.Sequence.lseq",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.append",
"Lib.Sequence.concat",
"Hacl.Spec.Bignum.Addition.bn_sub_carry_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Addition.bn_sub_carry",
"Prims.l_and",
"FStar.Seq.Base.slice",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.IntTypes.bits"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen
val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i))
let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1);
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
let rec bn_add_lemma_loop #t #aLen a b i =
let pbits = bits t in
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_add_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1));
bn_add_lemma_loop a b (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1));
bn_add_lemma_loop_step a b i (c1, res1);
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i);
() end
val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen)))
let bn_add_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_add_carry a1 c0 in
bn_add_carry_lemma a1 c0;
assert (v c1 * pow2 (pbits * (aLen - bLen)) + bn_v res1 == bn_v a1 + v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0 - v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c0) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - v c1 * pow2 (pbits * aLen);
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1) (v c0) }
eval_ bLen a0 bLen + eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 - v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (pbits * aLen);
}
val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_add a b in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b)
let bn_add_lemma #t #aLen #bLen a b =
let pbits = bits t in
let (c, res) = bn_add a b in
if bLen = aLen then
bn_add_lemma_loop a b aLen
else begin
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_add_f a0 b) (uint #t 0) in
bn_add_lemma_loop a0 b bLen;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #bLen res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma #t #aLen #bLen a b c0 res0 end
val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1)
let bn_add1_lemma #t #aLen a b1 =
let pbits = bits t in
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
assert (v c0 * pow2 pbits + v r0 = v a.[0] + v b1);
let res0 = create 1 r0 in
let b = create 1 b1 in
bn_eval1 res0;
bn_eval1 b;
if aLen = 1 then
bn_eval1 a
else begin
let bLen = 1 in
let a0 = sub a 0 bLen in
bn_eval1 a0;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #1 res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma a b c0 res0 end
val bn_sub_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) c1_res1 in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in))
let bn_sub_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let pbits = bits t in
let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_sub_carry_f a (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[i - 1] - v c1);
calc (==) {
bn_v #t #i res - v c * pow2 (pbits * i);
(==) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] - v e + v c * pow2 pbits) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i a i }
eval_ aLen a i - v c_in;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - v c_in)
val bn_sub_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in)
let rec bn_sub_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_sub_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in in
generate_elems_unfold aLen i (bn_sub_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_sub_carry_f a) c_in ==
generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1));
bn_sub_carry_lemma_loop a c_in (i - 1);
assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (pbits * (i - 1)) == eval_ aLen a (i - 1) - v c_in);
bn_sub_carry_lemma_loop_step a c_in i (c1, res1);
assert (bn_v #t #i res - v c_out * pow2 (pbits * i) == eval_ aLen a i - v c_in);
() end
val bn_sub_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_sub_carry a c_in in
bn_v res - v c_out * pow2 (bits t * aLen) == bn_v a - v c_in)
let bn_sub_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_sub_carry a c_in in
bn_sub_carry_lemma_loop a c_in aLen
val bn_sub_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1)))
(ensures
(let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) c1_res1 in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i))
let bn_sub_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) (c1, res1) in
let c, e = bn_sub_f a b (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[i - 1] - v b.[i - 1] - v c1);
calc (==) {
bn_v #t #i res - v c * pow2 (pbits * i);
(==) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits - v e) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1] - v b.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) - v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i a i }
eval_ aLen a i - eval_ aLen b (i - 1) - v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i b i }
eval_ aLen a i - eval_ aLen b i;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - eval_ aLen b i)
val bn_sub_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_f a b) (uint #t 0) in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i)
let rec bn_sub_lemma_loop #t #aLen a b i =
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_sub_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_sub_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_sub_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_sub_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_sub_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_sub_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_sub_f a b) (i - 1) (c1, res1));
bn_sub_lemma_loop a b (i - 1);
assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1));
bn_sub_lemma_loop_step a b i (c1, res1);
assert (bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i);
() end
val bn_sub_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
bn_v #t #bLen res0 - v c0 * pow2 (bits t * bLen) == eval_ bLen (sub a 0 bLen) bLen - eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen - eval_ bLen b bLen + v c1 * pow2 (bits t * aLen))) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
bn_v #t #bLen res0 - v c0 * pow2 (bits t * bLen) == eval_ bLen (sub a 0 bLen) bLen - eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen - eval_ bLen b bLen + v c1 * pow2 (bits t * aLen))) | [] | Hacl.Spec.Bignum.Addition.bn_sub_concat_lemma | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
b: Hacl.Spec.Bignum.Definitions.lbignum t bLen ->
c0: Hacl.Spec.Bignum.Base.carry t ->
res0: Hacl.Spec.Bignum.Definitions.lbignum t bLen
-> FStar.Pervasives.Lemma
(requires
Hacl.Spec.Bignum.Definitions.bn_v res0 -
Lib.IntTypes.v c0 * Prims.pow2 (Lib.IntTypes.bits t * bLen) ==
Hacl.Spec.Bignum.Definitions.eval_ bLen (Lib.Sequence.sub a 0 bLen) bLen -
Hacl.Spec.Bignum.Definitions.eval_ bLen b bLen)
(ensures
(let _ =
Hacl.Spec.Bignum.Addition.bn_sub_carry (Lib.Sequence.sub a bLen (aLen - bLen)) c0
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in
let res = Lib.Sequence.concat res0 res1 in
Hacl.Spec.Bignum.Definitions.bn_v res ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a aLen -
Hacl.Spec.Bignum.Definitions.eval_ bLen b bLen +
Lib.IntTypes.v c1 * Prims.pow2 (Lib.IntTypes.bits t * aLen))
<:
Type0)) | {
"end_col": 3,
"end_line": 515,
"start_col": 52,
"start_line": 491
} |
FStar.Pervasives.Lemma | val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen))) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_add_carry a1 c0 in
bn_add_carry_lemma a1 c0;
assert (v c1 * pow2 (pbits * (aLen - bLen)) + bn_v res1 == bn_v a1 + v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0 - v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c0) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - v c1 * pow2 (pbits * aLen);
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1) (v c0) }
eval_ bLen a0 bLen + eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 - v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (pbits * aLen);
} | val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen)))
let bn_add_concat_lemma #t #aLen #bLen a b c0 res0 = | false | null | true | let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_add_carry a1 c0 in
bn_add_carry_lemma a1 c0;
assert (v c1 * pow2 (pbits * (aLen - bLen)) + bn_v res1 == bn_v a1 + v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc ( == ) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
( == ) { () }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) +
pow2 (pbits * bLen) * (bn_v a1 + v c0 - v c1 * pow2 (pbits * (aLen - bLen)));
( == ) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen))
(bn_v a1 + v c0)
(v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) +
pow2 (pbits * bLen) * (bn_v a1 + v c0) -
(pow2 (pbits * bLen) * v c1) * pow2 (pbits * (aLen - bLen));
( == ) { (Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen)));
Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) +
pow2 (pbits * bLen) * (bn_v a1 + v c0) -
v c1 * pow2 (pbits * aLen);
( == ) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1) (v c0) }
eval_ bLen a0 bLen + eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 -
v c1 * pow2 (pbits * aLen);
( == ) { (bn_eval_split_i a bLen;
bn_eval_extensionality_j a (sub a 0 bLen) bLen) }
eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (pbits * aLen);
} | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.op_Subtraction",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Addition",
"Hacl.Spec.Bignum.Definitions.bn_v",
"FStar.Mul.op_Star",
"Prims.pow2",
"Hacl.Spec.Bignum.Definitions.eval_",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.distributivity_sub_right",
"FStar.Math.Lemmas.pow2_plus",
"FStar.Math.Lemmas.paren_mul_right",
"Hacl.Spec.Bignum.Definitions.bn_eval_extensionality_j",
"Lib.Sequence.sub",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Definitions.bn_eval_split_i",
"Prims._assert",
"Hacl.Spec.Bignum.Definitions.bn_concat_lemma",
"Lib.Sequence.lseq",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.append",
"Lib.Sequence.concat",
"Hacl.Spec.Bignum.Addition.bn_add_carry_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Addition.bn_add_carry",
"Prims.l_and",
"FStar.Seq.Base.slice",
"Prims.l_Forall",
"Prims.nat",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.index",
"Lib.IntTypes.bits"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen
val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i))
let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1);
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
let rec bn_add_lemma_loop #t #aLen a b i =
let pbits = bits t in
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_add_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1));
bn_add_lemma_loop a b (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1));
bn_add_lemma_loop_step a b i (c1, res1);
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i);
() end
val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen))) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen))) | [] | Hacl.Spec.Bignum.Addition.bn_add_concat_lemma | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
b: Hacl.Spec.Bignum.Definitions.lbignum t bLen ->
c0: Hacl.Spec.Bignum.Base.carry t ->
res0: Hacl.Spec.Bignum.Definitions.lbignum t bLen
-> FStar.Pervasives.Lemma
(requires
Lib.IntTypes.v c0 * Prims.pow2 (Lib.IntTypes.bits t * bLen) +
Hacl.Spec.Bignum.Definitions.bn_v res0 ==
Hacl.Spec.Bignum.Definitions.eval_ bLen (Lib.Sequence.sub a 0 bLen) bLen +
Hacl.Spec.Bignum.Definitions.eval_ bLen b bLen)
(ensures
(let _ =
Hacl.Spec.Bignum.Addition.bn_add_carry (Lib.Sequence.sub a bLen (aLen - bLen)) c0
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in
let res = Lib.Sequence.concat res0 res1 in
Hacl.Spec.Bignum.Definitions.bn_v res ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a aLen +
Hacl.Spec.Bignum.Definitions.eval_ bLen b bLen -
Lib.IntTypes.v c1 * Prims.pow2 (Lib.IntTypes.bits t * aLen))
<:
Type0)) | {
"end_col": 3,
"end_line": 267,
"start_col": 52,
"start_line": 243
} |
FStar.Pervasives.Lemma | val bn_sub_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) c1_res1 in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in)) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let pbits = bits t in
let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_sub_carry_f a (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[i - 1] - v c1);
calc (==) {
bn_v #t #i res - v c * pow2 (pbits * i);
(==) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] - v e + v c * pow2 pbits) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i a i }
eval_ aLen a i - v c_in;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - v c_in) | val bn_sub_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) c1_res1 in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in))
let bn_sub_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) = | false | null | true | let pbits = bits t in
let c_out, res = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_sub_carry_f a (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[ i - 1 ] - v c1);
calc ( == ) {
bn_v #t #i res - v c * pow2 (pbits * i);
( == ) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
( == ) { () }
eval_ aLen a (i - 1) - v c_in + (v a.[ i - 1 ] - v e + v c * pow2 pbits) * pow2 (pbits * (i - 1)) +
v e * pow2 (pbits * (i - 1)) -
v c * pow2 (pbits * i);
( == ) { Math.Lemmas.distributivity_sub_left (v a.[ i - 1 ] + v c * pow2 pbits)
(v e)
(pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + (v a.[ i - 1 ] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) -
v c * pow2 (pbits * i);
( == ) { Math.Lemmas.distributivity_add_left (v a.[ i - 1 ])
(v c * pow2 pbits)
(pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + v a.[ i - 1 ] * pow2 (pbits * (i - 1)) +
(v c * pow2 pbits) * pow2 (pbits * (i - 1)) -
v c * pow2 (pbits * i);
( == ) { (Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1)));
Math.Lemmas.pow2_plus pbits (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + v a.[ i - 1 ] * pow2 (pbits * (i - 1));
( == ) { bn_eval_unfold_i a i }
eval_ aLen a i - v c_in;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - v c_in) | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Lib.generate_elem_a",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.op_Subtraction",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.nat",
"Lib.Sequence.length",
"Prims.op_Addition",
"Prims._assert",
"Prims.int",
"Hacl.Spec.Bignum.Definitions.bn_v",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Hacl.Spec.Bignum.Definitions.eval_",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Lib.Sequence.op_String_Access",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.Bignum.Definitions.bn_eval_snoc",
"Prims.squash",
"FStar.Math.Lemmas.distributivity_sub_left",
"FStar.Math.Lemmas.distributivity_add_left",
"FStar.Math.Lemmas.pow2_plus",
"FStar.Math.Lemmas.paren_mul_right",
"Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Addition.bn_sub_carry_f",
"Hacl.Spec.Lib.generate_elem_f",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.bits"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen
val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i))
let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1);
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
let rec bn_add_lemma_loop #t #aLen a b i =
let pbits = bits t in
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_add_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1));
bn_add_lemma_loop a b (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1));
bn_add_lemma_loop_step a b i (c1, res1);
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i);
() end
val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen)))
let bn_add_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_add_carry a1 c0 in
bn_add_carry_lemma a1 c0;
assert (v c1 * pow2 (pbits * (aLen - bLen)) + bn_v res1 == bn_v a1 + v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0 - v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c0) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - v c1 * pow2 (pbits * aLen);
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1) (v c0) }
eval_ bLen a0 bLen + eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 - v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (pbits * aLen);
}
val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_add a b in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b)
let bn_add_lemma #t #aLen #bLen a b =
let pbits = bits t in
let (c, res) = bn_add a b in
if bLen = aLen then
bn_add_lemma_loop a b aLen
else begin
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_add_f a0 b) (uint #t 0) in
bn_add_lemma_loop a0 b bLen;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #bLen res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma #t #aLen #bLen a b c0 res0 end
val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1)
let bn_add1_lemma #t #aLen a b1 =
let pbits = bits t in
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
assert (v c0 * pow2 pbits + v r0 = v a.[0] + v b1);
let res0 = create 1 r0 in
let b = create 1 b1 in
bn_eval1 res0;
bn_eval1 b;
if aLen = 1 then
bn_eval1 a
else begin
let bLen = 1 in
let a0 = sub a 0 bLen in
bn_eval1 a0;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #1 res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma a b c0 res0 end
val bn_sub_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) c1_res1 in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in)) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) c1_res1 in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in)) | [] | Hacl.Spec.Bignum.Addition.bn_sub_carry_lemma_loop_step | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
c_in: Hacl.Spec.Bignum.Base.carry t ->
i: Prims.pos{i <= aLen} ->
c1_res1:
Hacl.Spec.Lib.generate_elem_a (Hacl.Spec.Bignum.Definitions.limb t)
(Hacl.Spec.Bignum.Base.carry t)
aLen
(i - 1)
-> FStar.Pervasives.Lemma
(requires
(let _ = c1_res1 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in
Hacl.Spec.Bignum.Definitions.bn_v res1 -
Lib.IntTypes.v c1 * Prims.pow2 (Lib.IntTypes.bits t * (i - 1)) ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a (i - 1) - Lib.IntTypes.v c_in)
<:
Type0))
(ensures
(let _ =
Hacl.Spec.Lib.generate_elem_f aLen
(Hacl.Spec.Bignum.Addition.bn_sub_carry_f a)
(i - 1)
c1_res1
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c_out res = _ in
Hacl.Spec.Bignum.Definitions.bn_v res -
Lib.IntTypes.v c_out * Prims.pow2 (Lib.IntTypes.bits t * i) ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a i - Lib.IntTypes.v c_in)
<:
Type0)) | {
"end_col": 77,
"end_line": 358,
"start_col": 63,
"start_line": 337
} |
FStar.Pervasives.Lemma | val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in) | val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) = | false | null | true | let c_out, res = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[ i - 1 ] + v c1);
let pbits = bits t in
calc ( == ) {
v c * pow2 (pbits * i) + bn_v #t #i res;
( == ) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
( == ) { () }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in -
(v e + v c * pow2 pbits - v a.[ i - 1 ]) * pow2 (pbits * (i - 1)) +
v e * pow2 (pbits * (i - 1));
( == ) { Math.Lemmas.distributivity_sub_left (v e)
(v e + v c * pow2 pbits - v a.[ i - 1 ])
(pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in +
(v e - v e - v c * pow2 pbits + v a.[ i - 1 ]) * pow2 (pbits * (i - 1));
( == ) { Math.Lemmas.distributivity_sub_left (v a.[ i - 1 ])
(v c * pow2 pbits)
(pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[ i - 1 ] * pow2 (pbits * (i - 1)) -
(v c * pow2 pbits) * pow2 (pbits * (i - 1));
( == ) { (Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1)));
Math.Lemmas.pow2_plus pbits (pbits * (i - 1))) }
eval_ aLen a (i - 1) + v c_in + v a.[ i - 1 ] * pow2 (pbits * (i - 1));
( == ) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in) | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Lib.generate_elem_a",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.op_Subtraction",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.nat",
"Lib.Sequence.length",
"Prims.op_Addition",
"Prims._assert",
"Prims.int",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.Definitions.eval_",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Lib.Sequence.op_String_Access",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.Bignum.Definitions.bn_eval_snoc",
"Prims.squash",
"FStar.Math.Lemmas.distributivity_sub_left",
"FStar.Math.Lemmas.pow2_plus",
"FStar.Math.Lemmas.paren_mul_right",
"Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i",
"Lib.IntTypes.bits",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Addition.bn_add_carry_f",
"Hacl.Spec.Lib.generate_elem_f",
"FStar.Pervasives.Native.Mktuple2"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)) | [] | Hacl.Spec.Bignum.Addition.bn_add_carry_lemma_loop_step | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
c_in: Hacl.Spec.Bignum.Base.carry t ->
i: Prims.pos{i <= aLen} ->
c1_res1:
Hacl.Spec.Lib.generate_elem_a (Hacl.Spec.Bignum.Definitions.limb t)
(Hacl.Spec.Bignum.Base.carry t)
aLen
(i - 1)
-> FStar.Pervasives.Lemma
(requires
(let _ = c1_res1 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in
Lib.IntTypes.v c1 * Prims.pow2 (Lib.IntTypes.bits t * (i - 1)) +
Hacl.Spec.Bignum.Definitions.bn_v res1 ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a (i - 1) + Lib.IntTypes.v c_in)
<:
Type0))
(ensures
(let _ =
Hacl.Spec.Lib.generate_elem_f aLen
(Hacl.Spec.Bignum.Addition.bn_add_carry_f a)
(i - 1)
c1_res1
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c_out res = _ in
Lib.IntTypes.v c_out * Prims.pow2 (Lib.IntTypes.bits t * i) +
Hacl.Spec.Bignum.Definitions.bn_v res ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a i + Lib.IntTypes.v c_in)
<:
Type0)) | {
"end_col": 77,
"end_line": 108,
"start_col": 63,
"start_line": 87
} |
FStar.Pervasives.Lemma | val bn_sub_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1)))
(ensures
(let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) c1_res1 in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i)) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_sub_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) (c1, res1) in
let c, e = bn_sub_f a b (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[i - 1] - v b.[i - 1] - v c1);
calc (==) {
bn_v #t #i res - v c * pow2 (pbits * i);
(==) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits - v e) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1] - v b.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + (v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) - v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i a i }
eval_ aLen a i - eval_ aLen b (i - 1) - v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i b i }
eval_ aLen a i - eval_ aLen b i;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - eval_ aLen b i) | val bn_sub_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1)))
(ensures
(let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) c1_res1 in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i))
let bn_sub_lemma_loop_step #t #aLen a b i (c1, res1) = | false | null | true | let pbits = bits t in
let c, res = generate_elem_f aLen (bn_sub_f a b) (i - 1) (c1, res1) in
let c, e = bn_sub_f a b (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[ i - 1 ] - v b.[ i - 1 ] - v c1);
calc ( == ) {
bn_v #t #i res - v c * pow2 (pbits * i);
( == ) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
( == ) { () }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) +
(v a.[ i - 1 ] - v b.[ i - 1 ] + v c * pow2 pbits - v e) * pow2 (pbits * (i - 1)) +
v e * pow2 (pbits * (i - 1)) -
v c * pow2 (pbits * i);
( == ) { Math.Lemmas.distributivity_sub_left (v a.[ i - 1 ] - v b.[ i - 1 ] + v c * pow2 pbits)
(v e)
(pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) +
(v a.[ i - 1 ] - v b.[ i - 1 ] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) -
v c * pow2 (pbits * i);
( == ) { Math.Lemmas.distributivity_add_left (v a.[ i - 1 ] - v b.[ i - 1 ])
(v c * pow2 pbits)
(pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) +
(v a.[ i - 1 ] - v b.[ i - 1 ]) * pow2 (pbits * (i - 1)) +
(v c * pow2 pbits) * pow2 (pbits * (i - 1)) -
v c * pow2 (pbits * i);
( == ) { (Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1)));
Math.Lemmas.pow2_plus pbits (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) +
(v a.[ i - 1 ] - v b.[ i - 1 ]) * pow2 (pbits * (i - 1));
( == ) { Math.Lemmas.distributivity_sub_left (v a.[ i - 1 ])
(v b.[ i - 1 ])
(pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - eval_ aLen b (i - 1) + v a.[ i - 1 ] * pow2 (pbits * (i - 1)) -
v b.[ i - 1 ] * pow2 (pbits * (i - 1));
( == ) { bn_eval_unfold_i a i }
eval_ aLen a i - eval_ aLen b (i - 1) - v b.[ i - 1 ] * pow2 (pbits * (i - 1));
( == ) { bn_eval_unfold_i b i }
eval_ aLen a i - eval_ aLen b i;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - eval_ aLen b i) | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Lib.generate_elem_a",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Base.carry",
"Prims.op_Subtraction",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.nat",
"Lib.Sequence.length",
"Prims.op_Addition",
"Prims._assert",
"Prims.int",
"Hacl.Spec.Bignum.Definitions.bn_v",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Hacl.Spec.Bignum.Definitions.eval_",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Lib.Sequence.op_String_Access",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.Bignum.Definitions.bn_eval_snoc",
"Prims.squash",
"FStar.Math.Lemmas.distributivity_sub_left",
"FStar.Math.Lemmas.distributivity_add_left",
"FStar.Math.Lemmas.pow2_plus",
"FStar.Math.Lemmas.paren_mul_right",
"Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Addition.bn_sub_f",
"Hacl.Spec.Lib.generate_elem_f",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.bits"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen
val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i))
let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1);
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
val bn_add_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:nat{i <= aLen} ->
Lemma (let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)
let rec bn_add_lemma_loop #t #aLen a b i =
let pbits = bits t in
let (c, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_f a b) (uint #t 0) in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_f a b) (uint #t 0);
assert (c == uint #t 0 /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
bn_eval0 b;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0) in
generate_elems_unfold aLen i (bn_add_f a b) (uint #t 0) (i - 1);
assert (generate_elems aLen i (bn_add_f a b) (uint #t 0) ==
generate_elem_f aLen (bn_add_f a b) (i - 1) (generate_elems aLen (i - 1) (bn_add_f a b) (uint #t 0)));
assert ((c, res) == generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1));
bn_add_lemma_loop a b (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1));
bn_add_lemma_loop_step a b i (c1, res1);
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i);
() end
val bn_add_concat_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen < aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen
-> c0:carry t
-> res0:lbignum t bLen -> Lemma
(requires
v c0 * pow2 (bits t * bLen) + bn_v #t #bLen res0 == eval_ bLen (sub a 0 bLen) bLen + eval_ bLen b bLen)
(ensures
(let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
let res = concat #_ #bLen res0 res1 in
bn_v res == eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (bits t * aLen)))
let bn_add_concat_lemma #t #aLen #bLen a b c0 res0 =
let pbits = bits t in
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c1, res1 = bn_add_carry a1 c0 in
bn_add_carry_lemma a1 c0;
assert (v c1 * pow2 (pbits * (aLen - bLen)) + bn_v res1 == bn_v a1 + v c0);
let res = concat #_ #bLen res0 res1 in
bn_concat_lemma res0 res1;
assert (bn_v res == bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1);
calc (==) {
bn_v #t #bLen res0 + pow2 (pbits * bLen) * bn_v res1;
(==) { }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0 - v c1 * pow2 (pbits * (aLen - bLen)));
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1 + v c0) (v c1 * pow2 (pbits * (aLen - bLen))) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - pow2 (pbits * bLen) * v c1 * pow2 (pbits * (aLen - bLen));
(==) { Math.Lemmas.paren_mul_right (pow2 (pbits * bLen)) (v c1) (pow2 (pbits * (aLen - bLen))); Math.Lemmas.pow2_plus (pbits * bLen) (pbits * (aLen - bLen)) }
eval_ bLen a0 bLen + eval_ bLen b bLen - v c0 * pow2 (pbits * bLen) + pow2 (pbits * bLen) * (bn_v a1 + v c0) - v c1 * pow2 (pbits * aLen);
(==) { Math.Lemmas.distributivity_sub_right (pow2 (pbits * bLen)) (bn_v a1) (v c0) }
eval_ bLen a0 bLen + eval_ bLen b bLen + pow2 (pbits * bLen) * bn_v a1 - v c1 * pow2 (pbits * aLen);
(==) { bn_eval_split_i a bLen; bn_eval_extensionality_j a (sub a 0 bLen) bLen }
eval_ aLen a aLen + eval_ bLen b bLen - v c1 * pow2 (pbits * aLen);
}
val bn_add_lemma:
#t:limb_t
-> #aLen:size_nat
-> #bLen:size_nat{bLen <= aLen}
-> a:lbignum t aLen
-> b:lbignum t bLen ->
Lemma (let (c, res) = bn_add a b in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + bn_v b)
let bn_add_lemma #t #aLen #bLen a b =
let pbits = bits t in
let (c, res) = bn_add a b in
if bLen = aLen then
bn_add_lemma_loop a b aLen
else begin
let a0 = sub a 0 bLen in
let a1 = sub a bLen (aLen - bLen) in
let c0, res0 = generate_elems bLen bLen (bn_add_f a0 b) (uint #t 0) in
bn_add_lemma_loop a0 b bLen;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #bLen res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma #t #aLen #bLen a b c0 res0 end
val bn_add1_lemma:
#t:limb_t
-> #aLen:size_pos
-> a:lbignum t aLen
-> b1:limb t ->
Lemma (let (c, res) = bn_add1 a b1 in
v c * pow2 (bits t * aLen) + bn_v res == bn_v a + v b1)
let bn_add1_lemma #t #aLen a b1 =
let pbits = bits t in
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
assert (v c0 * pow2 pbits + v r0 = v a.[0] + v b1);
let res0 = create 1 r0 in
let b = create 1 b1 in
bn_eval1 res0;
bn_eval1 b;
if aLen = 1 then
bn_eval1 a
else begin
let bLen = 1 in
let a0 = sub a 0 bLen in
bn_eval1 a0;
assert (v c0 * pow2 (pbits * bLen) + bn_v #t #1 res0 == eval_ bLen a0 bLen + eval_ bLen b bLen);
bn_add_concat_lemma a b c0 res0 end
val bn_sub_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) c1_res1 in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in))
let bn_sub_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let pbits = bits t in
let (c_out, res) = generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_sub_carry_f a (i - 1) c1 in
assert (v e - v c * pow2 pbits == v a.[i - 1] - v c1);
calc (==) {
bn_v #t #i res - v c * pow2 (pbits * i);
(==) { bn_eval_snoc #t #(i - 1) res1 e }
bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] - v e + v c * pow2 pbits) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v c * pow2 pbits) (v e) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + (v a.[i - 1] + v c * pow2 pbits) * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) + v c * pow2 pbits * pow2 (pbits * (i - 1)) - v c * pow2 (pbits * i);
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) - v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i a i }
eval_ aLen a i - v c_in;
};
assert (bn_v #t #i res - v c * pow2 (pbits * i) == eval_ aLen a i - v c_in)
val bn_sub_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
bn_v #t #i res - v c_out * pow2 (bits t * i) == eval_ aLen a i - v c_in)
let rec bn_sub_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_sub_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_sub_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in in
generate_elems_unfold aLen i (bn_sub_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_sub_carry_f a) c_in ==
generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_sub_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_sub_carry_f a) (i - 1) (c1, res1));
bn_sub_carry_lemma_loop a c_in (i - 1);
assert (bn_v #t #(i - 1) res1 - v c1 * pow2 (pbits * (i - 1)) == eval_ aLen a (i - 1) - v c_in);
bn_sub_carry_lemma_loop_step a c_in i (c1, res1);
assert (bn_v #t #i res - v c_out * pow2 (pbits * i) == eval_ aLen a i - v c_in);
() end
val bn_sub_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_sub_carry a c_in in
bn_v res - v c_out * pow2 (bits t * aLen) == bn_v a - v c_in)
let bn_sub_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_sub_carry a c_in in
bn_sub_carry_lemma_loop a c_in aLen
val bn_sub_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1)))
(ensures
(let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) c1_res1 in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i)) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_sub_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
bn_v #t #(i - 1) res1 - v c1 * pow2 (bits t * (i - 1)) == eval_ aLen a (i - 1) - eval_ aLen b (i - 1)))
(ensures
(let (c, res) = generate_elem_f aLen (bn_sub_f a b) (i - 1) c1_res1 in
bn_v #t #i res - v c * pow2 (bits t * i) == eval_ aLen a i - eval_ aLen b i)) | [] | Hacl.Spec.Bignum.Addition.bn_sub_lemma_loop_step | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
b: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
i: Prims.pos{i <= aLen} ->
c1_res1:
Hacl.Spec.Lib.generate_elem_a (Hacl.Spec.Bignum.Definitions.limb t)
(Hacl.Spec.Bignum.Base.carry t)
aLen
(i - 1)
-> FStar.Pervasives.Lemma
(requires
(let _ = c1_res1 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in
Hacl.Spec.Bignum.Definitions.bn_v res1 -
Lib.IntTypes.v c1 * Prims.pow2 (Lib.IntTypes.bits t * (i - 1)) ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a (i - 1) -
Hacl.Spec.Bignum.Definitions.eval_ aLen b (i - 1))
<:
Type0))
(ensures
(let _ =
Hacl.Spec.Lib.generate_elem_f aLen
(Hacl.Spec.Bignum.Addition.bn_sub_f a b)
(i - 1)
c1_res1
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
Hacl.Spec.Bignum.Definitions.bn_v res -
Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * i) ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a i -
Hacl.Spec.Bignum.Definitions.eval_ aLen b i)
<:
Type0)) | {
"end_col": 85,
"end_line": 441,
"start_col": 54,
"start_line": 416
} |
FStar.Pervasives.Lemma | val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)) | [
{
"abbrev": false,
"full_module": "Hacl.Spec.Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) =
let pbits = bits t in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[i - 1] + v b.[i - 1] + v c1);
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) - (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1] - v b.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v e - v e - v c * pow2 pbits + v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1] + v b.[i - 1]) (v c1 * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + (v a.[i - 1] + v b.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_add_left (v a.[i - 1]) (v b.[i - 1]) (pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[i - 1] * pow2 (pbits * (i - 1)) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i) | val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i))
let bn_add_lemma_loop_step #t #aLen a b i (c1, res1) = | false | null | true | let pbits = bits t in
let c, res = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
let c, e = bn_add_f a b (i - 1) c1 in
assert (v e + v c * pow2 pbits == v a.[ i - 1 ] + v b.[ i - 1 ] + v c1);
calc ( == ) {
v c * pow2 (pbits * i) + bn_v #t #i res;
( == ) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
( == ) { () }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) -
(v e + v c * pow2 pbits - v a.[ i - 1 ] - v b.[ i - 1 ]) * pow2 (pbits * (i - 1)) +
v e * pow2 (pbits * (i - 1));
( == ) { Math.Lemmas.distributivity_sub_left (v e)
(v e + v c * pow2 pbits - v a.[ i - 1 ] - v b.[ i - 1 ])
(pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) +
(v e - v e - v c * pow2 pbits + v a.[ i - 1 ] + v b.[ i - 1 ]) * pow2 (pbits * (i - 1));
( == ) { Math.Lemmas.distributivity_sub_left (v a.[ i - 1 ] + v b.[ i - 1 ])
(v c1 * pow2 pbits)
(pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + eval_ aLen b (i - 1) +
(v a.[ i - 1 ] + v b.[ i - 1 ]) * pow2 (pbits * (i - 1)) -
(v c * pow2 pbits) * pow2 (pbits * (i - 1));
( == ) { (Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1)));
Math.Lemmas.pow2_plus pbits (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) +
(v a.[ i - 1 ] + v b.[ i - 1 ]) * pow2 (pbits * (i - 1));
( == ) { Math.Lemmas.distributivity_add_left (v a.[ i - 1 ])
(v b.[ i - 1 ])
(pow2 (pbits * (i - 1))) }
eval_ aLen a (i - 1) + eval_ aLen b (i - 1) + v a.[ i - 1 ] * pow2 (pbits * (i - 1)) +
v b.[ i - 1 ] * pow2 (pbits * (i - 1));
( == ) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + eval_ aLen b (i - 1) + v b.[ i - 1 ] * pow2 (pbits * (i - 1));
( == ) { bn_eval_unfold_i #t #aLen b i }
eval_ aLen a i + eval_ aLen b i;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i) | {
"checked_file": "Hacl.Spec.Bignum.Addition.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Lib.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.Base.fst.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Bignum.Addition.fst"
} | [
"lemma"
] | [
"Hacl.Spec.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_nat",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.pos",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Hacl.Spec.Lib.generate_elem_a",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Base.carry",
"Prims.op_Subtraction",
"Lib.Sequence.seq",
"Prims.eq2",
"Prims.nat",
"Lib.Sequence.length",
"Prims.op_Addition",
"Prims._assert",
"Prims.int",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.Definitions.eval_",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Lib.Sequence.op_String_Access",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.Bignum.Definitions.bn_eval_snoc",
"Prims.squash",
"FStar.Math.Lemmas.distributivity_sub_left",
"FStar.Math.Lemmas.pow2_plus",
"FStar.Math.Lemmas.paren_mul_right",
"FStar.Math.Lemmas.distributivity_add_left",
"Hacl.Spec.Bignum.Definitions.bn_eval_unfold_i",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Addition.bn_add_f",
"Hacl.Spec.Lib.generate_elem_f",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.bits"
] | [] | module Hacl.Spec.Bignum.Addition
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Bignum.Definitions
open Hacl.Spec.Bignum.Base
open Hacl.Spec.Lib
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
val bn_sub_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_sub_carry_f #t #aLen a i c_in = subborrow c_in a.[i] (uint #t 0)
val bn_sub_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub_carry #t #aLen a c_in = generate_elems aLen aLen (bn_sub_carry_f a) c_in
val bn_sub_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_sub_f #t #aLen a b i c = subborrow c a.[i] b.[i]
val bn_sub: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> tuple2 (carry t) (lbignum t aLen)
let bn_sub #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_sub_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_sub_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_sub1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_sub1 #t #aLen a b1 =
let c0, r0 = subborrow (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_sub_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> i:size_nat{i < aLen} -> c_in:carry t -> carry t & limb t
let bn_add_carry_f #t #aLen a i c_in = addcarry c_in a.[i] (uint #t 0)
val bn_add_carry: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t -> tuple2 (carry t) (lbignum t aLen)
let bn_add_carry #t #aLen a c_in = generate_elems aLen aLen (bn_add_carry_f a) c_in
val bn_add_f: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> b:lbignum t aLen -> i:size_nat{i < aLen} -> c:carry t -> carry t & limb t
let bn_add_f #t #aLen a b i c = addcarry c a.[i] b.[i]
val bn_add: #t:limb_t -> #aLen:size_nat -> #bLen:size_nat{bLen <= aLen} -> a:lbignum t aLen -> b:lbignum t bLen -> carry t & lbignum t aLen
let bn_add #t #aLen #bLen a b =
let c0, res0 = generate_elems bLen bLen (bn_add_f (sub a 0 bLen) b) (uint #t 0) in
if bLen < aLen then
let c1, res1 = bn_add_carry (sub a bLen (aLen - bLen)) c0 in
c1, concat #_ #bLen res0 res1
else c0, res0
val bn_add1: #t:limb_t -> #aLen:size_pos -> a:lbignum t aLen -> b1:limb t -> tuple2 (carry t) (lbignum t aLen)
let bn_add1 #t #aLen a b1 =
let c0, r0 = addcarry (uint #t 0) a.[0] b1 in
let res0 = create 1 r0 in
if 1 < aLen then
let c1, res1 = bn_add_carry (sub a 1 (aLen - 1)) c0 in
c1, concat res0 res1
else c0, res0
val bn_add_carry_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in))
(ensures
(let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) c1_res1 in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in))
let bn_add_carry_lemma_loop_step #t #aLen a c_in i (c1, res1) =
let (c_out, res) = generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1) in
let c, e = bn_add_carry_f a (i - 1) c1 in
assert (v e + v c * pow2 (bits t) == v a.[i - 1] + v c1);
let pbits = bits t in
calc (==) {
v c * pow2 (pbits * i) + bn_v #t #i res;
(==) { bn_eval_snoc #t #(i - 1) res1 e }
v c * pow2 (pbits * i) + bn_v #t #(i - 1) res1 + v e * pow2 (pbits * (i - 1));
(==) { }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in - (v e + v c * pow2 pbits - v a.[i - 1]) * pow2 (pbits * (i - 1)) + v e * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v e) (v e + v c * pow2 pbits - v a.[i - 1]) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + (v e - v e - v c * pow2 pbits + v a.[i - 1]) * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.distributivity_sub_left (v a.[i - 1]) (v c * pow2 pbits) (pow2 (pbits * (i - 1))) }
v c * pow2 (pbits * i) + eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1)) - v c * pow2 pbits * pow2 (pbits * (i - 1));
(==) { Math.Lemmas.paren_mul_right (v c) (pow2 pbits) (pow2 (pbits * (i - 1))); Math.Lemmas.pow2_plus pbits (pbits * (i - 1)) }
eval_ aLen a (i - 1) + v c_in + v a.[i - 1] * pow2 (pbits * (i - 1));
(==) { bn_eval_unfold_i #t #aLen a i }
eval_ aLen a i + v c_in;
};
assert (v c * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
val bn_add_carry_lemma_loop:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> c_in:carry t
-> i:nat{i <= aLen} ->
Lemma (let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
v c_out * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + v c_in)
let rec bn_add_carry_lemma_loop #t #aLen a c_in i =
let pbits = bits t in
let (c_out, res) : generate_elem_a (limb t) (carry t) aLen i = generate_elems aLen i (bn_add_carry_f a) c_in in
if i = 0 then begin
eq_generate_elems0 aLen i (bn_add_carry_f a) c_in;
assert (c_out == c_in /\ res == Seq.empty);
bn_eval0 #t #0 res;
assert_norm (pow2 0 = 1);
bn_eval0 a;
() end
else begin
let (c1, res1) : generate_elem_a (limb t) (carry t) aLen (i - 1) = generate_elems aLen (i - 1) (bn_add_carry_f a) c_in in
generate_elems_unfold aLen i (bn_add_carry_f a) c_in (i - 1);
assert (generate_elems aLen i (bn_add_carry_f a) c_in ==
generate_elem_f aLen (bn_add_carry_f a) (i - 1) (generate_elems aLen (i - 1) (bn_add_carry_f a) c_in));
assert ((c_out, res) == generate_elem_f aLen (bn_add_carry_f a) (i - 1) (c1, res1));
bn_add_carry_lemma_loop a c_in (i - 1);
assert (v c1 * pow2 (pbits * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + v c_in);
bn_add_carry_lemma_loop_step a c_in i (c1, res1);
assert (v c_out * pow2 (pbits * i) + bn_v #t #i res == eval_ aLen a i + v c_in);
() end
val bn_add_carry_lemma: #t:limb_t -> #aLen:size_nat -> a:lbignum t aLen -> c_in:carry t ->
Lemma (let (c_out, res) = bn_add_carry a c_in in
v c_out * pow2 (bits t * aLen) + bn_v res == bn_v a + v c_in)
let bn_add_carry_lemma #t #aLen a c_in =
let (c_out, res) = bn_add_carry a c_in in
bn_add_carry_lemma_loop a c_in aLen
val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)) | false | false | Hacl.Spec.Bignum.Addition.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_add_lemma_loop_step:
#t:limb_t
-> #aLen:size_nat
-> a:lbignum t aLen
-> b:lbignum t aLen
-> i:pos{i <= aLen}
-> c1_res1:generate_elem_a (limb t) (carry t) aLen (i - 1) -> Lemma
(requires
(let (c1, res1) = c1_res1 in
v c1 * pow2 (bits t * (i - 1)) + bn_v #t #(i - 1) res1 == eval_ aLen a (i - 1) + eval_ aLen b (i - 1)))
(ensures
(let (c1, res1) = c1_res1 in
let (c, res) = generate_elem_f aLen (bn_add_f a b) (i - 1) (c1, res1) in
v c * pow2 (bits t * i) + bn_v #t #i res == eval_ aLen a i + eval_ aLen b i)) | [] | Hacl.Spec.Bignum.Addition.bn_add_lemma_loop_step | {
"file_name": "code/bignum/Hacl.Spec.Bignum.Addition.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
b: Hacl.Spec.Bignum.Definitions.lbignum t aLen ->
i: Prims.pos{i <= aLen} ->
c1_res1:
Hacl.Spec.Lib.generate_elem_a (Hacl.Spec.Bignum.Definitions.limb t)
(Hacl.Spec.Bignum.Base.carry t)
aLen
(i - 1)
-> FStar.Pervasives.Lemma
(requires
(let _ = c1_res1 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in
Lib.IntTypes.v c1 * Prims.pow2 (Lib.IntTypes.bits t * (i - 1)) +
Hacl.Spec.Bignum.Definitions.bn_v res1 ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a (i - 1) +
Hacl.Spec.Bignum.Definitions.eval_ aLen b (i - 1))
<:
Type0))
(ensures
(let _ = c1_res1 in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c1 res1 = _ in
let _ =
Hacl.Spec.Lib.generate_elem_f aLen
(Hacl.Spec.Bignum.Addition.bn_add_f a b)
(i - 1)
(c1, res1)
in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c res = _ in
Lib.IntTypes.v c * Prims.pow2 (Lib.IntTypes.bits t * i) +
Hacl.Spec.Bignum.Definitions.bn_v res ==
Hacl.Spec.Bignum.Definitions.eval_ aLen a i +
Hacl.Spec.Bignum.Definitions.eval_ aLen b i)
<:
Type0)
<:
Type0)) | {
"end_col": 85,
"end_line": 192,
"start_col": 54,
"start_line": 167
} |
FStar.Tactics.Effect.Tac | val get_max_ifuel: Prims.unit -> Tac int | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get_max_ifuel () : Tac int = (get_vconfig ()).max_ifuel | val get_max_ifuel: Prims.unit -> Tac int
let get_max_ifuel () : Tac int = | true | null | false | (get_vconfig ()).max_ifuel | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.unit",
"FStar.VConfig.__proj__Mkvconfig__item__max_ifuel",
"Prims.int",
"FStar.VConfig.vconfig",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig
(* Alias to just use the current vconfig *)
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
(* smt_sync': as smt_sync, but using a particular fuel/ifuel *)
let smt_sync' (fuel ifuel : nat) : Tac unit =
let vcfg = get_vconfig () in
let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel
; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg'
(* Getting/setting solver configuration *)
let get_rlimit () : Tac int = (get_vconfig()).z3rlimit
let set_rlimit (v : int) : Tac unit = set_vconfig { get_vconfig () with z3rlimit = v }
let get_initial_fuel () : Tac int = (get_vconfig ()).initial_fuel
let get_initial_ifuel () : Tac int = (get_vconfig ()).initial_ifuel | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_max_ifuel: Prims.unit -> Tac int | [] | FStar.Tactics.SMT.get_max_ifuel | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.int | {
"end_col": 71,
"end_line": 26,
"start_col": 45,
"start_line": 26
} |
FStar.Tactics.Effect.Tac | val get_initial_ifuel: Prims.unit -> Tac int | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get_initial_ifuel () : Tac int = (get_vconfig ()).initial_ifuel | val get_initial_ifuel: Prims.unit -> Tac int
let get_initial_ifuel () : Tac int = | true | null | false | (get_vconfig ()).initial_ifuel | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.unit",
"FStar.VConfig.__proj__Mkvconfig__item__initial_ifuel",
"Prims.int",
"FStar.VConfig.vconfig",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig
(* Alias to just use the current vconfig *)
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
(* smt_sync': as smt_sync, but using a particular fuel/ifuel *)
let smt_sync' (fuel ifuel : nat) : Tac unit =
let vcfg = get_vconfig () in
let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel
; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg'
(* Getting/setting solver configuration *)
let get_rlimit () : Tac int = (get_vconfig()).z3rlimit
let set_rlimit (v : int) : Tac unit = set_vconfig { get_vconfig () with z3rlimit = v } | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_initial_ifuel: Prims.unit -> Tac int | [] | FStar.Tactics.SMT.get_initial_ifuel | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.int | {
"end_col": 75,
"end_line": 24,
"start_col": 45,
"start_line": 24
} |
FStar.Tactics.Effect.Tac | val set_fuel (v: int) : Tac unit | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let set_fuel (v : int) : Tac unit = set_vconfig { get_vconfig () with initial_fuel = v; max_fuel = v } | val set_fuel (v: int) : Tac unit
let set_fuel (v: int) : Tac unit = | true | null | false | set_vconfig ({ get_vconfig () with initial_fuel = v; max_fuel = v }) | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.int",
"FStar.Tactics.V2.Builtins.set_vconfig",
"Prims.unit",
"FStar.VConfig.vconfig",
"FStar.VConfig.Mkvconfig",
"FStar.VConfig.__proj__Mkvconfig__item__initial_ifuel",
"FStar.VConfig.__proj__Mkvconfig__item__max_ifuel",
"FStar.VConfig.__proj__Mkvconfig__item__detail_errors",
"FStar.VConfig.__proj__Mkvconfig__item__detail_hint_replay",
"FStar.VConfig.__proj__Mkvconfig__item__no_smt",
"FStar.VConfig.__proj__Mkvconfig__item__quake_lo",
"FStar.VConfig.__proj__Mkvconfig__item__quake_hi",
"FStar.VConfig.__proj__Mkvconfig__item__quake_keep",
"FStar.VConfig.__proj__Mkvconfig__item__retry",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_elim_box",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_nl_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_l_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_intro",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_elim",
"FStar.VConfig.__proj__Mkvconfig__item__tcnorm",
"FStar.VConfig.__proj__Mkvconfig__item__no_plugins",
"FStar.VConfig.__proj__Mkvconfig__item__no_tactics",
"FStar.VConfig.__proj__Mkvconfig__item__z3cliopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3smtopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3refresh",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit_factor",
"FStar.VConfig.__proj__Mkvconfig__item__z3seed",
"FStar.VConfig.__proj__Mkvconfig__item__z3version",
"FStar.VConfig.__proj__Mkvconfig__item__trivial_pre_for_unannotated_effectful_fns",
"FStar.VConfig.__proj__Mkvconfig__item__reuse_hint_for",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig
(* Alias to just use the current vconfig *)
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
(* smt_sync': as smt_sync, but using a particular fuel/ifuel *)
let smt_sync' (fuel ifuel : nat) : Tac unit =
let vcfg = get_vconfig () in
let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel
; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg'
(* Getting/setting solver configuration *)
let get_rlimit () : Tac int = (get_vconfig()).z3rlimit
let set_rlimit (v : int) : Tac unit = set_vconfig { get_vconfig () with z3rlimit = v }
let get_initial_fuel () : Tac int = (get_vconfig ()).initial_fuel
let get_initial_ifuel () : Tac int = (get_vconfig ()).initial_ifuel
let get_max_fuel () : Tac int = (get_vconfig ()).max_fuel
let get_max_ifuel () : Tac int = (get_vconfig ()).max_ifuel
let set_initial_fuel (v : int) : Tac unit = set_vconfig { get_vconfig () with initial_fuel = v }
let set_initial_ifuel (v : int) : Tac unit = set_vconfig { get_vconfig () with initial_ifuel = v }
let set_max_fuel (v : int) : Tac unit = set_vconfig { get_vconfig () with max_fuel = v }
let set_max_ifuel (v : int) : Tac unit = set_vconfig { get_vconfig () with max_ifuel = v } | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val set_fuel (v: int) : Tac unit | [] | FStar.Tactics.SMT.set_fuel | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: Prims.int -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 113,
"end_line": 34,
"start_col": 45,
"start_line": 34
} |
FStar.Tactics.Effect.Tac | val set_initial_fuel (v: int) : Tac unit | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let set_initial_fuel (v : int) : Tac unit = set_vconfig { get_vconfig () with initial_fuel = v } | val set_initial_fuel (v: int) : Tac unit
let set_initial_fuel (v: int) : Tac unit = | true | null | false | set_vconfig ({ get_vconfig () with initial_fuel = v }) | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.int",
"FStar.Tactics.V2.Builtins.set_vconfig",
"Prims.unit",
"FStar.VConfig.vconfig",
"FStar.VConfig.Mkvconfig",
"FStar.VConfig.__proj__Mkvconfig__item__max_fuel",
"FStar.VConfig.__proj__Mkvconfig__item__initial_ifuel",
"FStar.VConfig.__proj__Mkvconfig__item__max_ifuel",
"FStar.VConfig.__proj__Mkvconfig__item__detail_errors",
"FStar.VConfig.__proj__Mkvconfig__item__detail_hint_replay",
"FStar.VConfig.__proj__Mkvconfig__item__no_smt",
"FStar.VConfig.__proj__Mkvconfig__item__quake_lo",
"FStar.VConfig.__proj__Mkvconfig__item__quake_hi",
"FStar.VConfig.__proj__Mkvconfig__item__quake_keep",
"FStar.VConfig.__proj__Mkvconfig__item__retry",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_elim_box",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_nl_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_l_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_intro",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_elim",
"FStar.VConfig.__proj__Mkvconfig__item__tcnorm",
"FStar.VConfig.__proj__Mkvconfig__item__no_plugins",
"FStar.VConfig.__proj__Mkvconfig__item__no_tactics",
"FStar.VConfig.__proj__Mkvconfig__item__z3cliopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3smtopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3refresh",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit_factor",
"FStar.VConfig.__proj__Mkvconfig__item__z3seed",
"FStar.VConfig.__proj__Mkvconfig__item__z3version",
"FStar.VConfig.__proj__Mkvconfig__item__trivial_pre_for_unannotated_effectful_fns",
"FStar.VConfig.__proj__Mkvconfig__item__reuse_hint_for",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig
(* Alias to just use the current vconfig *)
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
(* smt_sync': as smt_sync, but using a particular fuel/ifuel *)
let smt_sync' (fuel ifuel : nat) : Tac unit =
let vcfg = get_vconfig () in
let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel
; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg'
(* Getting/setting solver configuration *)
let get_rlimit () : Tac int = (get_vconfig()).z3rlimit
let set_rlimit (v : int) : Tac unit = set_vconfig { get_vconfig () with z3rlimit = v }
let get_initial_fuel () : Tac int = (get_vconfig ()).initial_fuel
let get_initial_ifuel () : Tac int = (get_vconfig ()).initial_ifuel
let get_max_fuel () : Tac int = (get_vconfig ()).max_fuel
let get_max_ifuel () : Tac int = (get_vconfig ()).max_ifuel | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val set_initial_fuel (v: int) : Tac unit | [] | FStar.Tactics.SMT.set_initial_fuel | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: Prims.int -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 98,
"end_line": 28,
"start_col": 45,
"start_line": 28
} |
FStar.Tactics.Effect.Tac | val get_max_fuel: Prims.unit -> Tac int | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get_max_fuel () : Tac int = (get_vconfig ()).max_fuel | val get_max_fuel: Prims.unit -> Tac int
let get_max_fuel () : Tac int = | true | null | false | (get_vconfig ()).max_fuel | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.unit",
"FStar.VConfig.__proj__Mkvconfig__item__max_fuel",
"Prims.int",
"FStar.VConfig.vconfig",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig
(* Alias to just use the current vconfig *)
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
(* smt_sync': as smt_sync, but using a particular fuel/ifuel *)
let smt_sync' (fuel ifuel : nat) : Tac unit =
let vcfg = get_vconfig () in
let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel
; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg'
(* Getting/setting solver configuration *)
let get_rlimit () : Tac int = (get_vconfig()).z3rlimit
let set_rlimit (v : int) : Tac unit = set_vconfig { get_vconfig () with z3rlimit = v }
let get_initial_fuel () : Tac int = (get_vconfig ()).initial_fuel | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_max_fuel: Prims.unit -> Tac int | [] | FStar.Tactics.SMT.get_max_fuel | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.int | {
"end_col": 70,
"end_line": 25,
"start_col": 45,
"start_line": 25
} |
FStar.Tactics.Effect.Tac | val smt_sync: Prims.unit -> Tac unit | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let smt_sync () : Tac unit = t_smt_sync (get_vconfig ()) | val smt_sync: Prims.unit -> Tac unit
let smt_sync () : Tac unit = | true | null | false | t_smt_sync (get_vconfig ()) | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V2.Builtins.t_smt_sync",
"FStar.VConfig.vconfig",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val smt_sync: Prims.unit -> Tac unit | [] | FStar.Tactics.SMT.smt_sync | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 56,
"end_line": 8,
"start_col": 29,
"start_line": 8
} |
FStar.Tactics.Effect.Tac | val get_rlimit: Prims.unit -> Tac int | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get_rlimit () : Tac int = (get_vconfig()).z3rlimit | val get_rlimit: Prims.unit -> Tac int
let get_rlimit () : Tac int = | true | null | false | (get_vconfig ()).z3rlimit | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.unit",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit",
"Prims.int",
"FStar.VConfig.vconfig",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig
(* Alias to just use the current vconfig *)
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
(* smt_sync': as smt_sync, but using a particular fuel/ifuel *)
let smt_sync' (fuel ifuel : nat) : Tac unit =
let vcfg = get_vconfig () in
let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel
; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg'
(* Getting/setting solver configuration *) | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_rlimit: Prims.unit -> Tac int | [] | FStar.Tactics.SMT.get_rlimit | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.int | {
"end_col": 69,
"end_line": 20,
"start_col": 45,
"start_line": 20
} |
FStar.Tactics.Effect.Tac | val set_initial_ifuel (v: int) : Tac unit | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let set_initial_ifuel (v : int) : Tac unit = set_vconfig { get_vconfig () with initial_ifuel = v } | val set_initial_ifuel (v: int) : Tac unit
let set_initial_ifuel (v: int) : Tac unit = | true | null | false | set_vconfig ({ get_vconfig () with initial_ifuel = v }) | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.int",
"FStar.Tactics.V2.Builtins.set_vconfig",
"Prims.unit",
"FStar.VConfig.vconfig",
"FStar.VConfig.Mkvconfig",
"FStar.VConfig.__proj__Mkvconfig__item__initial_fuel",
"FStar.VConfig.__proj__Mkvconfig__item__max_fuel",
"FStar.VConfig.__proj__Mkvconfig__item__max_ifuel",
"FStar.VConfig.__proj__Mkvconfig__item__detail_errors",
"FStar.VConfig.__proj__Mkvconfig__item__detail_hint_replay",
"FStar.VConfig.__proj__Mkvconfig__item__no_smt",
"FStar.VConfig.__proj__Mkvconfig__item__quake_lo",
"FStar.VConfig.__proj__Mkvconfig__item__quake_hi",
"FStar.VConfig.__proj__Mkvconfig__item__quake_keep",
"FStar.VConfig.__proj__Mkvconfig__item__retry",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_elim_box",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_nl_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_l_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_intro",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_elim",
"FStar.VConfig.__proj__Mkvconfig__item__tcnorm",
"FStar.VConfig.__proj__Mkvconfig__item__no_plugins",
"FStar.VConfig.__proj__Mkvconfig__item__no_tactics",
"FStar.VConfig.__proj__Mkvconfig__item__z3cliopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3smtopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3refresh",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit_factor",
"FStar.VConfig.__proj__Mkvconfig__item__z3seed",
"FStar.VConfig.__proj__Mkvconfig__item__z3version",
"FStar.VConfig.__proj__Mkvconfig__item__trivial_pre_for_unannotated_effectful_fns",
"FStar.VConfig.__proj__Mkvconfig__item__reuse_hint_for",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig
(* Alias to just use the current vconfig *)
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
(* smt_sync': as smt_sync, but using a particular fuel/ifuel *)
let smt_sync' (fuel ifuel : nat) : Tac unit =
let vcfg = get_vconfig () in
let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel
; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg'
(* Getting/setting solver configuration *)
let get_rlimit () : Tac int = (get_vconfig()).z3rlimit
let set_rlimit (v : int) : Tac unit = set_vconfig { get_vconfig () with z3rlimit = v }
let get_initial_fuel () : Tac int = (get_vconfig ()).initial_fuel
let get_initial_ifuel () : Tac int = (get_vconfig ()).initial_ifuel
let get_max_fuel () : Tac int = (get_vconfig ()).max_fuel
let get_max_ifuel () : Tac int = (get_vconfig ()).max_ifuel | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val set_initial_ifuel (v: int) : Tac unit | [] | FStar.Tactics.SMT.set_initial_ifuel | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: Prims.int -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 98,
"end_line": 29,
"start_col": 45,
"start_line": 29
} |
FStar.Tactics.Effect.Tac | val get_initial_fuel: Prims.unit -> Tac int | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let get_initial_fuel () : Tac int = (get_vconfig ()).initial_fuel | val get_initial_fuel: Prims.unit -> Tac int
let get_initial_fuel () : Tac int = | true | null | false | (get_vconfig ()).initial_fuel | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.unit",
"FStar.VConfig.__proj__Mkvconfig__item__initial_fuel",
"Prims.int",
"FStar.VConfig.vconfig",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig
(* Alias to just use the current vconfig *)
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
(* smt_sync': as smt_sync, but using a particular fuel/ifuel *)
let smt_sync' (fuel ifuel : nat) : Tac unit =
let vcfg = get_vconfig () in
let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel
; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg'
(* Getting/setting solver configuration *)
let get_rlimit () : Tac int = (get_vconfig()).z3rlimit
let set_rlimit (v : int) : Tac unit = set_vconfig { get_vconfig () with z3rlimit = v } | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val get_initial_fuel: Prims.unit -> Tac int | [] | FStar.Tactics.SMT.get_initial_fuel | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.int | {
"end_col": 74,
"end_line": 23,
"start_col": 45,
"start_line": 23
} |
FStar.Tactics.Effect.Tac | val smt_sync' (fuel ifuel: nat) : Tac unit | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let smt_sync' (fuel ifuel : nat) : Tac unit =
let vcfg = get_vconfig () in
let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel
; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg' | val smt_sync' (fuel ifuel: nat) : Tac unit
let smt_sync' (fuel ifuel: nat) : Tac unit = | true | null | false | let vcfg = get_vconfig () in
let vcfg' =
{ vcfg with initial_fuel = fuel; max_fuel = fuel; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg' | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.nat",
"FStar.Tactics.V2.Builtins.t_smt_sync",
"Prims.unit",
"FStar.VConfig.vconfig",
"FStar.VConfig.Mkvconfig",
"FStar.VConfig.__proj__Mkvconfig__item__detail_errors",
"FStar.VConfig.__proj__Mkvconfig__item__detail_hint_replay",
"FStar.VConfig.__proj__Mkvconfig__item__no_smt",
"FStar.VConfig.__proj__Mkvconfig__item__quake_lo",
"FStar.VConfig.__proj__Mkvconfig__item__quake_hi",
"FStar.VConfig.__proj__Mkvconfig__item__quake_keep",
"FStar.VConfig.__proj__Mkvconfig__item__retry",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_elim_box",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_nl_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_l_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_intro",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_elim",
"FStar.VConfig.__proj__Mkvconfig__item__tcnorm",
"FStar.VConfig.__proj__Mkvconfig__item__no_plugins",
"FStar.VConfig.__proj__Mkvconfig__item__no_tactics",
"FStar.VConfig.__proj__Mkvconfig__item__z3cliopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3smtopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3refresh",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit_factor",
"FStar.VConfig.__proj__Mkvconfig__item__z3seed",
"FStar.VConfig.__proj__Mkvconfig__item__z3version",
"FStar.VConfig.__proj__Mkvconfig__item__trivial_pre_for_unannotated_effectful_fns",
"FStar.VConfig.__proj__Mkvconfig__item__reuse_hint_for",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig
(* Alias to just use the current vconfig *)
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ()) | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val smt_sync' (fuel ifuel: nat) : Tac unit | [] | FStar.Tactics.SMT.smt_sync' | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | fuel: Prims.nat -> ifuel: Prims.nat -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 20,
"end_line": 16,
"start_col": 45,
"start_line": 11
} |
FStar.Tactics.Effect.Tac | val set_rlimit (v: int) : Tac unit | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let set_rlimit (v : int) : Tac unit = set_vconfig { get_vconfig () with z3rlimit = v } | val set_rlimit (v: int) : Tac unit
let set_rlimit (v: int) : Tac unit = | true | null | false | set_vconfig ({ get_vconfig () with z3rlimit = v }) | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.int",
"FStar.Tactics.V2.Builtins.set_vconfig",
"Prims.unit",
"FStar.VConfig.vconfig",
"FStar.VConfig.Mkvconfig",
"FStar.VConfig.__proj__Mkvconfig__item__initial_fuel",
"FStar.VConfig.__proj__Mkvconfig__item__max_fuel",
"FStar.VConfig.__proj__Mkvconfig__item__initial_ifuel",
"FStar.VConfig.__proj__Mkvconfig__item__max_ifuel",
"FStar.VConfig.__proj__Mkvconfig__item__detail_errors",
"FStar.VConfig.__proj__Mkvconfig__item__detail_hint_replay",
"FStar.VConfig.__proj__Mkvconfig__item__no_smt",
"FStar.VConfig.__proj__Mkvconfig__item__quake_lo",
"FStar.VConfig.__proj__Mkvconfig__item__quake_hi",
"FStar.VConfig.__proj__Mkvconfig__item__quake_keep",
"FStar.VConfig.__proj__Mkvconfig__item__retry",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_elim_box",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_nl_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_l_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_intro",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_elim",
"FStar.VConfig.__proj__Mkvconfig__item__tcnorm",
"FStar.VConfig.__proj__Mkvconfig__item__no_plugins",
"FStar.VConfig.__proj__Mkvconfig__item__no_tactics",
"FStar.VConfig.__proj__Mkvconfig__item__z3cliopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3smtopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3refresh",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit_factor",
"FStar.VConfig.__proj__Mkvconfig__item__z3seed",
"FStar.VConfig.__proj__Mkvconfig__item__z3version",
"FStar.VConfig.__proj__Mkvconfig__item__trivial_pre_for_unannotated_effectful_fns",
"FStar.VConfig.__proj__Mkvconfig__item__reuse_hint_for",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig
(* Alias to just use the current vconfig *)
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
(* smt_sync': as smt_sync, but using a particular fuel/ifuel *)
let smt_sync' (fuel ifuel : nat) : Tac unit =
let vcfg = get_vconfig () in
let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel
; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg'
(* Getting/setting solver configuration *) | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val set_rlimit (v: int) : Tac unit | [] | FStar.Tactics.SMT.set_rlimit | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: Prims.int -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 93,
"end_line": 21,
"start_col": 45,
"start_line": 21
} |
FStar.Tactics.Effect.Tac | val set_max_ifuel (v: int) : Tac unit | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let set_max_ifuel (v : int) : Tac unit = set_vconfig { get_vconfig () with max_ifuel = v } | val set_max_ifuel (v: int) : Tac unit
let set_max_ifuel (v: int) : Tac unit = | true | null | false | set_vconfig ({ get_vconfig () with max_ifuel = v }) | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.int",
"FStar.Tactics.V2.Builtins.set_vconfig",
"Prims.unit",
"FStar.VConfig.vconfig",
"FStar.VConfig.Mkvconfig",
"FStar.VConfig.__proj__Mkvconfig__item__initial_fuel",
"FStar.VConfig.__proj__Mkvconfig__item__max_fuel",
"FStar.VConfig.__proj__Mkvconfig__item__initial_ifuel",
"FStar.VConfig.__proj__Mkvconfig__item__detail_errors",
"FStar.VConfig.__proj__Mkvconfig__item__detail_hint_replay",
"FStar.VConfig.__proj__Mkvconfig__item__no_smt",
"FStar.VConfig.__proj__Mkvconfig__item__quake_lo",
"FStar.VConfig.__proj__Mkvconfig__item__quake_hi",
"FStar.VConfig.__proj__Mkvconfig__item__quake_keep",
"FStar.VConfig.__proj__Mkvconfig__item__retry",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_elim_box",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_nl_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_l_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_intro",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_elim",
"FStar.VConfig.__proj__Mkvconfig__item__tcnorm",
"FStar.VConfig.__proj__Mkvconfig__item__no_plugins",
"FStar.VConfig.__proj__Mkvconfig__item__no_tactics",
"FStar.VConfig.__proj__Mkvconfig__item__z3cliopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3smtopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3refresh",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit_factor",
"FStar.VConfig.__proj__Mkvconfig__item__z3seed",
"FStar.VConfig.__proj__Mkvconfig__item__z3version",
"FStar.VConfig.__proj__Mkvconfig__item__trivial_pre_for_unannotated_effectful_fns",
"FStar.VConfig.__proj__Mkvconfig__item__reuse_hint_for",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig
(* Alias to just use the current vconfig *)
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
(* smt_sync': as smt_sync, but using a particular fuel/ifuel *)
let smt_sync' (fuel ifuel : nat) : Tac unit =
let vcfg = get_vconfig () in
let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel
; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg'
(* Getting/setting solver configuration *)
let get_rlimit () : Tac int = (get_vconfig()).z3rlimit
let set_rlimit (v : int) : Tac unit = set_vconfig { get_vconfig () with z3rlimit = v }
let get_initial_fuel () : Tac int = (get_vconfig ()).initial_fuel
let get_initial_ifuel () : Tac int = (get_vconfig ()).initial_ifuel
let get_max_fuel () : Tac int = (get_vconfig ()).max_fuel
let get_max_ifuel () : Tac int = (get_vconfig ()).max_ifuel
let set_initial_fuel (v : int) : Tac unit = set_vconfig { get_vconfig () with initial_fuel = v }
let set_initial_ifuel (v : int) : Tac unit = set_vconfig { get_vconfig () with initial_ifuel = v } | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val set_max_ifuel (v: int) : Tac unit | [] | FStar.Tactics.SMT.set_max_ifuel | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: Prims.int -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 98,
"end_line": 31,
"start_col": 45,
"start_line": 31
} |
FStar.Tactics.Effect.Tac | val set_max_fuel (v: int) : Tac unit | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let set_max_fuel (v : int) : Tac unit = set_vconfig { get_vconfig () with max_fuel = v } | val set_max_fuel (v: int) : Tac unit
let set_max_fuel (v: int) : Tac unit = | true | null | false | set_vconfig ({ get_vconfig () with max_fuel = v }) | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.int",
"FStar.Tactics.V2.Builtins.set_vconfig",
"Prims.unit",
"FStar.VConfig.vconfig",
"FStar.VConfig.Mkvconfig",
"FStar.VConfig.__proj__Mkvconfig__item__initial_fuel",
"FStar.VConfig.__proj__Mkvconfig__item__initial_ifuel",
"FStar.VConfig.__proj__Mkvconfig__item__max_ifuel",
"FStar.VConfig.__proj__Mkvconfig__item__detail_errors",
"FStar.VConfig.__proj__Mkvconfig__item__detail_hint_replay",
"FStar.VConfig.__proj__Mkvconfig__item__no_smt",
"FStar.VConfig.__proj__Mkvconfig__item__quake_lo",
"FStar.VConfig.__proj__Mkvconfig__item__quake_hi",
"FStar.VConfig.__proj__Mkvconfig__item__quake_keep",
"FStar.VConfig.__proj__Mkvconfig__item__retry",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_elim_box",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_nl_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_l_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_intro",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_elim",
"FStar.VConfig.__proj__Mkvconfig__item__tcnorm",
"FStar.VConfig.__proj__Mkvconfig__item__no_plugins",
"FStar.VConfig.__proj__Mkvconfig__item__no_tactics",
"FStar.VConfig.__proj__Mkvconfig__item__z3cliopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3smtopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3refresh",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit_factor",
"FStar.VConfig.__proj__Mkvconfig__item__z3seed",
"FStar.VConfig.__proj__Mkvconfig__item__z3version",
"FStar.VConfig.__proj__Mkvconfig__item__trivial_pre_for_unannotated_effectful_fns",
"FStar.VConfig.__proj__Mkvconfig__item__reuse_hint_for",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig
(* Alias to just use the current vconfig *)
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
(* smt_sync': as smt_sync, but using a particular fuel/ifuel *)
let smt_sync' (fuel ifuel : nat) : Tac unit =
let vcfg = get_vconfig () in
let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel
; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg'
(* Getting/setting solver configuration *)
let get_rlimit () : Tac int = (get_vconfig()).z3rlimit
let set_rlimit (v : int) : Tac unit = set_vconfig { get_vconfig () with z3rlimit = v }
let get_initial_fuel () : Tac int = (get_vconfig ()).initial_fuel
let get_initial_ifuel () : Tac int = (get_vconfig ()).initial_ifuel
let get_max_fuel () : Tac int = (get_vconfig ()).max_fuel
let get_max_ifuel () : Tac int = (get_vconfig ()).max_ifuel
let set_initial_fuel (v : int) : Tac unit = set_vconfig { get_vconfig () with initial_fuel = v } | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val set_max_fuel (v: int) : Tac unit | [] | FStar.Tactics.SMT.set_max_fuel | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: Prims.int -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 98,
"end_line": 30,
"start_col": 45,
"start_line": 30
} |
FStar.Tactics.Effect.Tac | val set_ifuel (v: int) : Tac unit | [
{
"abbrev": false,
"full_module": "FStar.VConfig",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.V2.Builtins",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Effect",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let set_ifuel (v : int) : Tac unit = set_vconfig { get_vconfig () with initial_ifuel = v; max_ifuel = v } | val set_ifuel (v: int) : Tac unit
let set_ifuel (v: int) : Tac unit = | true | null | false | set_vconfig ({ get_vconfig () with initial_ifuel = v; max_ifuel = v }) | {
"checked_file": "FStar.Tactics.SMT.fst.checked",
"dependencies": [
"prims.fst.checked",
"FStar.VConfig.fsti.checked",
"FStar.Tactics.V2.Builtins.fsti.checked",
"FStar.Tactics.Effect.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.SMT.fst"
} | [] | [
"Prims.int",
"FStar.Tactics.V2.Builtins.set_vconfig",
"Prims.unit",
"FStar.VConfig.vconfig",
"FStar.VConfig.Mkvconfig",
"FStar.VConfig.__proj__Mkvconfig__item__initial_fuel",
"FStar.VConfig.__proj__Mkvconfig__item__max_fuel",
"FStar.VConfig.__proj__Mkvconfig__item__detail_errors",
"FStar.VConfig.__proj__Mkvconfig__item__detail_hint_replay",
"FStar.VConfig.__proj__Mkvconfig__item__no_smt",
"FStar.VConfig.__proj__Mkvconfig__item__quake_lo",
"FStar.VConfig.__proj__Mkvconfig__item__quake_hi",
"FStar.VConfig.__proj__Mkvconfig__item__quake_keep",
"FStar.VConfig.__proj__Mkvconfig__item__retry",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_elim_box",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_nl_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_l_arith_repr",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_intro",
"FStar.VConfig.__proj__Mkvconfig__item__smtencoding_valid_elim",
"FStar.VConfig.__proj__Mkvconfig__item__tcnorm",
"FStar.VConfig.__proj__Mkvconfig__item__no_plugins",
"FStar.VConfig.__proj__Mkvconfig__item__no_tactics",
"FStar.VConfig.__proj__Mkvconfig__item__z3cliopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3smtopt",
"FStar.VConfig.__proj__Mkvconfig__item__z3refresh",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit",
"FStar.VConfig.__proj__Mkvconfig__item__z3rlimit_factor",
"FStar.VConfig.__proj__Mkvconfig__item__z3seed",
"FStar.VConfig.__proj__Mkvconfig__item__z3version",
"FStar.VConfig.__proj__Mkvconfig__item__trivial_pre_for_unannotated_effectful_fns",
"FStar.VConfig.__proj__Mkvconfig__item__reuse_hint_for",
"FStar.Tactics.V2.Builtins.get_vconfig"
] | [] | module FStar.Tactics.SMT
open FStar.Tactics.Effect
open FStar.Tactics.V2.Builtins
open FStar.VConfig
(* Alias to just use the current vconfig *)
let smt_sync () : Tac unit = t_smt_sync (get_vconfig ())
(* smt_sync': as smt_sync, but using a particular fuel/ifuel *)
let smt_sync' (fuel ifuel : nat) : Tac unit =
let vcfg = get_vconfig () in
let vcfg' = { vcfg with initial_fuel = fuel; max_fuel = fuel
; initial_ifuel = ifuel; max_ifuel = ifuel }
in
t_smt_sync vcfg'
(* Getting/setting solver configuration *)
let get_rlimit () : Tac int = (get_vconfig()).z3rlimit
let set_rlimit (v : int) : Tac unit = set_vconfig { get_vconfig () with z3rlimit = v }
let get_initial_fuel () : Tac int = (get_vconfig ()).initial_fuel
let get_initial_ifuel () : Tac int = (get_vconfig ()).initial_ifuel
let get_max_fuel () : Tac int = (get_vconfig ()).max_fuel
let get_max_ifuel () : Tac int = (get_vconfig ()).max_ifuel
let set_initial_fuel (v : int) : Tac unit = set_vconfig { get_vconfig () with initial_fuel = v }
let set_initial_ifuel (v : int) : Tac unit = set_vconfig { get_vconfig () with initial_ifuel = v }
let set_max_fuel (v : int) : Tac unit = set_vconfig { get_vconfig () with max_fuel = v }
let set_max_ifuel (v : int) : Tac unit = set_vconfig { get_vconfig () with max_ifuel = v }
(* Set both min and max *) | false | false | FStar.Tactics.SMT.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val set_ifuel (v: int) : Tac unit | [] | FStar.Tactics.SMT.set_ifuel | {
"file_name": "ulib/FStar.Tactics.SMT.fst",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | v: Prims.int -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 113,
"end_line": 35,
"start_col": 45,
"start_line": 35
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum25519",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let point_inv_full_t (h:mem) (p:point) =
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p) | let point_inv_full_t (h: mem) (p: point) = | false | null | false | F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p) | {
"checked_file": "Hacl.Impl.Ed25519.Verify.fst.checked",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.SHA512.ModQ.fst.checked",
"Hacl.Impl.Load56.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Ed25519.Verify.fst"
} | [
"total"
] | [
"FStar.Monotonic.HyperStack.mem",
"Hacl.Bignum25519.point",
"Prims.l_and",
"Hacl.Impl.Ed25519.Field51.point_inv_t",
"Hacl.Impl.Ed25519.Field51.inv_ext_point",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint64",
"FStar.UInt32.__uint_to_t",
"Prims.logical"
] | [] | module Hacl.Impl.Ed25519.Verify
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module BSeq = Lib.ByteSequence
open Hacl.Bignum25519
module F51 = Hacl.Impl.Ed25519.Field51
module PM = Hacl.Impl.Ed25519.Ladder
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract | false | true | Hacl.Impl.Ed25519.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val point_inv_full_t : h: FStar.Monotonic.HyperStack.mem -> p: Hacl.Bignum25519.point -> Prims.logical | [] | Hacl.Impl.Ed25519.Verify.point_inv_full_t | {
"file_name": "code/ed25519/Hacl.Impl.Ed25519.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | h: FStar.Monotonic.HyperStack.mem -> p: Hacl.Bignum25519.point -> Prims.logical | {
"end_col": 55,
"end_line": 21,
"start_col": 2,
"start_line": 21
} |
|
FStar.HyperStack.ST.Stack | val verify_sb: sb:lbuffer uint8 32ul -> Stack bool
(requires fun h -> live h sb)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(b <==> (BSeq.nat_from_bytes_le (as_seq h0 sb) >= Spec.Ed25519.q))) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum25519",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let verify_sb sb =
push_frame ();
let tmp = create 5ul (u64 0) in
Hacl.Impl.Load56.load_32_bytes tmp sb;
let b = Hacl.Impl.Ed25519.PointEqual.gte_q tmp in
pop_frame ();
b | val verify_sb: sb:lbuffer uint8 32ul -> Stack bool
(requires fun h -> live h sb)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(b <==> (BSeq.nat_from_bytes_le (as_seq h0 sb) >= Spec.Ed25519.q)))
let verify_sb sb = | true | null | false | push_frame ();
let tmp = create 5ul (u64 0) in
Hacl.Impl.Load56.load_32_bytes tmp sb;
let b = Hacl.Impl.Ed25519.PointEqual.gte_q tmp in
pop_frame ();
b | {
"checked_file": "Hacl.Impl.Ed25519.Verify.fst.checked",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.SHA512.ModQ.fst.checked",
"Hacl.Impl.Load56.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Ed25519.Verify.fst"
} | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Prims.bool",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Hacl.Impl.Ed25519.PointEqual.gte_q",
"Hacl.Impl.Load56.load_32_bytes",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.uint64",
"Lib.IntTypes.u64",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.Ed25519.Verify
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module BSeq = Lib.ByteSequence
open Hacl.Bignum25519
module F51 = Hacl.Impl.Ed25519.Field51
module PM = Hacl.Impl.Ed25519.Ladder
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let point_inv_full_t (h:mem) (p:point) =
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p)
inline_for_extraction noextract
val verify_all_valid_hb (sb hb:lbuffer uint8 32ul) (a' r':point) : Stack bool
(requires fun h ->
live h sb /\ live h hb /\ live h a' /\ live h r' /\
point_inv_full_t h a' /\ point_inv_full_t h r')
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
(z == Spec.Ed25519.(
let exp_d = point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a') in
point_equal exp_d (F51.point_eval h0 r'))))
let verify_all_valid_hb sb hb a' r' =
push_frame ();
let exp_d = create 20ul (u64 0) in
PM.point_negate_mul_double_g_vartime exp_d sb hb a';
let b = Hacl.Impl.Ed25519.PointEqual.point_equal exp_d r' in
let h0 = ST.get () in
Spec.Ed25519.Lemmas.point_equal_lemma
(F51.point_eval h0 exp_d)
(Spec.Ed25519.point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a'))
(F51.point_eval h0 r');
pop_frame ();
b
inline_for_extraction noextract
val verify_sb: sb:lbuffer uint8 32ul -> Stack bool
(requires fun h -> live h sb)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(b <==> (BSeq.nat_from_bytes_le (as_seq h0 sb) >= Spec.Ed25519.q))) | false | false | Hacl.Impl.Ed25519.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val verify_sb: sb:lbuffer uint8 32ul -> Stack bool
(requires fun h -> live h sb)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(b <==> (BSeq.nat_from_bytes_le (as_seq h0 sb) >= Spec.Ed25519.q))) | [] | Hacl.Impl.Ed25519.Verify.verify_sb | {
"file_name": "code/ed25519/Hacl.Impl.Ed25519.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | sb: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 3,
"end_line": 60,
"start_col": 2,
"start_line": 55
} |
FStar.HyperStack.ST.Stack | val verify:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature)
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature)) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum25519",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let verify public_key msg_len msg signature =
push_frame ();
let a' = create 20ul (u64 0) in
let h0 = ST.get () in
Spec.Ed25519.Lemmas.point_decompress_lemma (as_seq h0 public_key);
let b = Hacl.Impl.Ed25519.PointDecompress.point_decompress a' public_key in
let res = if b then verify_valid_pk public_key msg_len msg signature a' else false in
pop_frame ();
res | val verify:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature)
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature))
let verify public_key msg_len msg signature = | true | null | false | push_frame ();
let a' = create 20ul (u64 0) in
let h0 = ST.get () in
Spec.Ed25519.Lemmas.point_decompress_lemma (as_seq h0 public_key);
let b = Hacl.Impl.Ed25519.PointDecompress.point_decompress a' public_key in
let res = if b then verify_valid_pk public_key msg_len msg signature a' else false in
pop_frame ();
res | {
"checked_file": "Hacl.Impl.Ed25519.Verify.fst.checked",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.SHA512.ModQ.fst.checked",
"Hacl.Impl.Load56.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Ed25519.Verify.fst"
} | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.size_t",
"Prims.bool",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Hacl.Impl.Ed25519.Verify.verify_valid_pk",
"Hacl.Impl.Ed25519.PointDecompress.point_decompress",
"Spec.Ed25519.Lemmas.point_decompress_lemma",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.uint64",
"Lib.IntTypes.u64",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.Ed25519.Verify
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module BSeq = Lib.ByteSequence
open Hacl.Bignum25519
module F51 = Hacl.Impl.Ed25519.Field51
module PM = Hacl.Impl.Ed25519.Ladder
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let point_inv_full_t (h:mem) (p:point) =
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p)
inline_for_extraction noextract
val verify_all_valid_hb (sb hb:lbuffer uint8 32ul) (a' r':point) : Stack bool
(requires fun h ->
live h sb /\ live h hb /\ live h a' /\ live h r' /\
point_inv_full_t h a' /\ point_inv_full_t h r')
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
(z == Spec.Ed25519.(
let exp_d = point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a') in
point_equal exp_d (F51.point_eval h0 r'))))
let verify_all_valid_hb sb hb a' r' =
push_frame ();
let exp_d = create 20ul (u64 0) in
PM.point_negate_mul_double_g_vartime exp_d sb hb a';
let b = Hacl.Impl.Ed25519.PointEqual.point_equal exp_d r' in
let h0 = ST.get () in
Spec.Ed25519.Lemmas.point_equal_lemma
(F51.point_eval h0 exp_d)
(Spec.Ed25519.point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a'))
(F51.point_eval h0 r');
pop_frame ();
b
inline_for_extraction noextract
val verify_sb: sb:lbuffer uint8 32ul -> Stack bool
(requires fun h -> live h sb)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(b <==> (BSeq.nat_from_bytes_le (as_seq h0 sb) >= Spec.Ed25519.q)))
let verify_sb sb =
push_frame ();
let tmp = create 5ul (u64 0) in
Hacl.Impl.Load56.load_32_bytes tmp sb;
let b = Hacl.Impl.Ed25519.PointEqual.gte_q tmp in
pop_frame ();
b
inline_for_extraction noextract
val verify_valid_pk_rs:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul
-> a':point
-> r':point ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature /\ live h a' /\ live h r' /\
(Some? (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ point_inv_full_t h a' /\
(F51.point_eval h a' == Some?.v (Spec.Ed25519.point_decompress (as_seq h public_key))) /\
(Some? (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul)))) /\ point_inv_full_t h r' /\
(F51.point_eval h r' == Some?.v (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul)))))
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature))
let verify_valid_pk_rs public_key msg_len msg signature a' r' =
push_frame ();
let hb = create 32ul (u8 0) in
let rs = sub signature 0ul 32ul in
let sb = sub signature 32ul 32ul in
let b = verify_sb sb in
let res =
if b then false
else begin
Hacl.Impl.SHA512.ModQ.store_sha512_modq_pre_pre2 hb rs public_key msg_len msg;
verify_all_valid_hb sb hb a' r' end in
pop_frame ();
res
inline_for_extraction noextract
val verify_valid_pk:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul
-> a':point ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature /\ live h a' /\
(Some? (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ point_inv_full_t h a' /\
(F51.point_eval h a' == Some?.v (Spec.Ed25519.point_decompress (as_seq h public_key))))
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature))
let verify_valid_pk public_key msg_len msg signature a' =
push_frame ();
let r' = create 20ul (u64 0) in
let rs = sub signature 0ul 32ul in
let h0 = ST.get () in
Spec.Ed25519.Lemmas.point_decompress_lemma (as_seq h0 rs);
let b' = Hacl.Impl.Ed25519.PointDecompress.point_decompress r' rs in
let res = if b' then verify_valid_pk_rs public_key msg_len msg signature a' r' else false in
pop_frame ();
res
inline_for_extraction noextract
val verify:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature)
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature)) | false | false | Hacl.Impl.Ed25519.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val verify:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature)
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature)) | [] | Hacl.Impl.Ed25519.Verify.verify | {
"file_name": "code/ed25519/Hacl.Impl.Ed25519.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
public_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
msg_len: Lib.IntTypes.size_t ->
msg: Lib.Buffer.lbuffer Lib.IntTypes.uint8 msg_len ->
signature: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 5,
"end_line": 144,
"start_col": 2,
"start_line": 137
} |
FStar.HyperStack.ST.Stack | val verify_all_valid_hb (sb hb:lbuffer uint8 32ul) (a' r':point) : Stack bool
(requires fun h ->
live h sb /\ live h hb /\ live h a' /\ live h r' /\
point_inv_full_t h a' /\ point_inv_full_t h r')
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
(z == Spec.Ed25519.(
let exp_d = point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a') in
point_equal exp_d (F51.point_eval h0 r')))) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum25519",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let verify_all_valid_hb sb hb a' r' =
push_frame ();
let exp_d = create 20ul (u64 0) in
PM.point_negate_mul_double_g_vartime exp_d sb hb a';
let b = Hacl.Impl.Ed25519.PointEqual.point_equal exp_d r' in
let h0 = ST.get () in
Spec.Ed25519.Lemmas.point_equal_lemma
(F51.point_eval h0 exp_d)
(Spec.Ed25519.point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a'))
(F51.point_eval h0 r');
pop_frame ();
b | val verify_all_valid_hb (sb hb:lbuffer uint8 32ul) (a' r':point) : Stack bool
(requires fun h ->
live h sb /\ live h hb /\ live h a' /\ live h r' /\
point_inv_full_t h a' /\ point_inv_full_t h r')
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
(z == Spec.Ed25519.(
let exp_d = point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a') in
point_equal exp_d (F51.point_eval h0 r'))))
let verify_all_valid_hb sb hb a' r' = | true | null | false | push_frame ();
let exp_d = create 20ul (u64 0) in
PM.point_negate_mul_double_g_vartime exp_d sb hb a';
let b = Hacl.Impl.Ed25519.PointEqual.point_equal exp_d r' in
let h0 = ST.get () in
Spec.Ed25519.Lemmas.point_equal_lemma (F51.point_eval h0 exp_d)
(Spec.Ed25519.point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a'))
(F51.point_eval h0 r');
pop_frame ();
b | {
"checked_file": "Hacl.Impl.Ed25519.Verify.fst.checked",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.SHA512.ModQ.fst.checked",
"Hacl.Impl.Load56.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Ed25519.Verify.fst"
} | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Hacl.Bignum25519.point",
"Prims.bool",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Spec.Ed25519.Lemmas.point_equal_lemma",
"Hacl.Impl.Ed25519.Field51.point_eval",
"Spec.Ed25519.point_negate_mul_double_g",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Impl.Ed25519.PointEqual.point_equal",
"Hacl.Impl.Ed25519.Ladder.point_negate_mul_double_g_vartime",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.uint64",
"Lib.IntTypes.u64",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.Ed25519.Verify
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module BSeq = Lib.ByteSequence
open Hacl.Bignum25519
module F51 = Hacl.Impl.Ed25519.Field51
module PM = Hacl.Impl.Ed25519.Ladder
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let point_inv_full_t (h:mem) (p:point) =
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p)
inline_for_extraction noextract
val verify_all_valid_hb (sb hb:lbuffer uint8 32ul) (a' r':point) : Stack bool
(requires fun h ->
live h sb /\ live h hb /\ live h a' /\ live h r' /\
point_inv_full_t h a' /\ point_inv_full_t h r')
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
(z == Spec.Ed25519.(
let exp_d = point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a') in
point_equal exp_d (F51.point_eval h0 r')))) | false | false | Hacl.Impl.Ed25519.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val verify_all_valid_hb (sb hb:lbuffer uint8 32ul) (a' r':point) : Stack bool
(requires fun h ->
live h sb /\ live h hb /\ live h a' /\ live h r' /\
point_inv_full_t h a' /\ point_inv_full_t h r')
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
(z == Spec.Ed25519.(
let exp_d = point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a') in
point_equal exp_d (F51.point_eval h0 r')))) | [] | Hacl.Impl.Ed25519.Verify.verify_all_valid_hb | {
"file_name": "code/ed25519/Hacl.Impl.Ed25519.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
sb: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
hb: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
a': Hacl.Bignum25519.point ->
r': Hacl.Bignum25519.point
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 3,
"end_line": 45,
"start_col": 2,
"start_line": 35
} |
FStar.HyperStack.ST.Stack | val verify_valid_pk:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul
-> a':point ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature /\ live h a' /\
(Some? (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ point_inv_full_t h a' /\
(F51.point_eval h a' == Some?.v (Spec.Ed25519.point_decompress (as_seq h public_key))))
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature)) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum25519",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let verify_valid_pk public_key msg_len msg signature a' =
push_frame ();
let r' = create 20ul (u64 0) in
let rs = sub signature 0ul 32ul in
let h0 = ST.get () in
Spec.Ed25519.Lemmas.point_decompress_lemma (as_seq h0 rs);
let b' = Hacl.Impl.Ed25519.PointDecompress.point_decompress r' rs in
let res = if b' then verify_valid_pk_rs public_key msg_len msg signature a' r' else false in
pop_frame ();
res | val verify_valid_pk:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul
-> a':point ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature /\ live h a' /\
(Some? (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ point_inv_full_t h a' /\
(F51.point_eval h a' == Some?.v (Spec.Ed25519.point_decompress (as_seq h public_key))))
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature))
let verify_valid_pk public_key msg_len msg signature a' = | true | null | false | push_frame ();
let r' = create 20ul (u64 0) in
let rs = sub signature 0ul 32ul in
let h0 = ST.get () in
Spec.Ed25519.Lemmas.point_decompress_lemma (as_seq h0 rs);
let b' = Hacl.Impl.Ed25519.PointDecompress.point_decompress r' rs in
let res = if b' then verify_valid_pk_rs public_key msg_len msg signature a' r' else false in
pop_frame ();
res | {
"checked_file": "Hacl.Impl.Ed25519.Verify.fst.checked",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.SHA512.ModQ.fst.checked",
"Hacl.Impl.Load56.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Ed25519.Verify.fst"
} | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum25519.point",
"Prims.bool",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Hacl.Impl.Ed25519.Verify.verify_valid_pk_rs",
"Hacl.Impl.Ed25519.PointDecompress.point_decompress",
"Spec.Ed25519.Lemmas.point_decompress_lemma",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"Lib.IntTypes.U64",
"Lib.Buffer.create",
"Lib.IntTypes.uint64",
"Lib.IntTypes.u64",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.Ed25519.Verify
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module BSeq = Lib.ByteSequence
open Hacl.Bignum25519
module F51 = Hacl.Impl.Ed25519.Field51
module PM = Hacl.Impl.Ed25519.Ladder
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let point_inv_full_t (h:mem) (p:point) =
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p)
inline_for_extraction noextract
val verify_all_valid_hb (sb hb:lbuffer uint8 32ul) (a' r':point) : Stack bool
(requires fun h ->
live h sb /\ live h hb /\ live h a' /\ live h r' /\
point_inv_full_t h a' /\ point_inv_full_t h r')
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
(z == Spec.Ed25519.(
let exp_d = point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a') in
point_equal exp_d (F51.point_eval h0 r'))))
let verify_all_valid_hb sb hb a' r' =
push_frame ();
let exp_d = create 20ul (u64 0) in
PM.point_negate_mul_double_g_vartime exp_d sb hb a';
let b = Hacl.Impl.Ed25519.PointEqual.point_equal exp_d r' in
let h0 = ST.get () in
Spec.Ed25519.Lemmas.point_equal_lemma
(F51.point_eval h0 exp_d)
(Spec.Ed25519.point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a'))
(F51.point_eval h0 r');
pop_frame ();
b
inline_for_extraction noextract
val verify_sb: sb:lbuffer uint8 32ul -> Stack bool
(requires fun h -> live h sb)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(b <==> (BSeq.nat_from_bytes_le (as_seq h0 sb) >= Spec.Ed25519.q)))
let verify_sb sb =
push_frame ();
let tmp = create 5ul (u64 0) in
Hacl.Impl.Load56.load_32_bytes tmp sb;
let b = Hacl.Impl.Ed25519.PointEqual.gte_q tmp in
pop_frame ();
b
inline_for_extraction noextract
val verify_valid_pk_rs:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul
-> a':point
-> r':point ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature /\ live h a' /\ live h r' /\
(Some? (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ point_inv_full_t h a' /\
(F51.point_eval h a' == Some?.v (Spec.Ed25519.point_decompress (as_seq h public_key))) /\
(Some? (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul)))) /\ point_inv_full_t h r' /\
(F51.point_eval h r' == Some?.v (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul)))))
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature))
let verify_valid_pk_rs public_key msg_len msg signature a' r' =
push_frame ();
let hb = create 32ul (u8 0) in
let rs = sub signature 0ul 32ul in
let sb = sub signature 32ul 32ul in
let b = verify_sb sb in
let res =
if b then false
else begin
Hacl.Impl.SHA512.ModQ.store_sha512_modq_pre_pre2 hb rs public_key msg_len msg;
verify_all_valid_hb sb hb a' r' end in
pop_frame ();
res
inline_for_extraction noextract
val verify_valid_pk:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul
-> a':point ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature /\ live h a' /\
(Some? (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ point_inv_full_t h a' /\
(F51.point_eval h a' == Some?.v (Spec.Ed25519.point_decompress (as_seq h public_key))))
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature)) | false | false | Hacl.Impl.Ed25519.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val verify_valid_pk:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul
-> a':point ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature /\ live h a' /\
(Some? (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ point_inv_full_t h a' /\
(F51.point_eval h a' == Some?.v (Spec.Ed25519.point_decompress (as_seq h public_key))))
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature)) | [] | Hacl.Impl.Ed25519.Verify.verify_valid_pk | {
"file_name": "code/ed25519/Hacl.Impl.Ed25519.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
public_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
msg_len: Lib.IntTypes.size_t ->
msg: Lib.Buffer.lbuffer Lib.IntTypes.uint8 msg_len ->
signature: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul ->
a': Hacl.Bignum25519.point
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 5,
"end_line": 121,
"start_col": 2,
"start_line": 113
} |
FStar.HyperStack.ST.Stack | val verify_valid_pk_rs:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul
-> a':point
-> r':point ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature /\ live h a' /\ live h r' /\
(Some? (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ point_inv_full_t h a' /\
(F51.point_eval h a' == Some?.v (Spec.Ed25519.point_decompress (as_seq h public_key))) /\
(Some? (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul)))) /\ point_inv_full_t h r' /\
(F51.point_eval h r' == Some?.v (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul)))))
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature)) | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "PM"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum25519",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Ed25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let verify_valid_pk_rs public_key msg_len msg signature a' r' =
push_frame ();
let hb = create 32ul (u8 0) in
let rs = sub signature 0ul 32ul in
let sb = sub signature 32ul 32ul in
let b = verify_sb sb in
let res =
if b then false
else begin
Hacl.Impl.SHA512.ModQ.store_sha512_modq_pre_pre2 hb rs public_key msg_len msg;
verify_all_valid_hb sb hb a' r' end in
pop_frame ();
res | val verify_valid_pk_rs:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul
-> a':point
-> r':point ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature /\ live h a' /\ live h r' /\
(Some? (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ point_inv_full_t h a' /\
(F51.point_eval h a' == Some?.v (Spec.Ed25519.point_decompress (as_seq h public_key))) /\
(Some? (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul)))) /\ point_inv_full_t h r' /\
(F51.point_eval h r' == Some?.v (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul)))))
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature))
let verify_valid_pk_rs public_key msg_len msg signature a' r' = | true | null | false | push_frame ();
let hb = create 32ul (u8 0) in
let rs = sub signature 0ul 32ul in
let sb = sub signature 32ul 32ul in
let b = verify_sb sb in
let res =
if b
then false
else
(Hacl.Impl.SHA512.ModQ.store_sha512_modq_pre_pre2 hb rs public_key msg_len msg;
verify_all_valid_hb sb hb a' r')
in
pop_frame ();
res | {
"checked_file": "Hacl.Impl.Ed25519.Verify.fst.checked",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.SHA512.ModQ.fst.checked",
"Hacl.Impl.Load56.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Bignum25519.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Ed25519.Verify.fst"
} | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum25519.point",
"Prims.bool",
"Prims.unit",
"FStar.HyperStack.ST.pop_frame",
"Hacl.Impl.Ed25519.Verify.verify_all_valid_hb",
"Hacl.Impl.SHA512.ModQ.store_sha512_modq_pre_pre2",
"Hacl.Impl.Ed25519.Verify.verify_sb",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.sub",
"Lib.Buffer.create",
"Lib.IntTypes.u8",
"FStar.HyperStack.ST.push_frame"
] | [] | module Hacl.Impl.Ed25519.Verify
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module BSeq = Lib.ByteSequence
open Hacl.Bignum25519
module F51 = Hacl.Impl.Ed25519.Field51
module PM = Hacl.Impl.Ed25519.Ladder
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let point_inv_full_t (h:mem) (p:point) =
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p)
inline_for_extraction noextract
val verify_all_valid_hb (sb hb:lbuffer uint8 32ul) (a' r':point) : Stack bool
(requires fun h ->
live h sb /\ live h hb /\ live h a' /\ live h r' /\
point_inv_full_t h a' /\ point_inv_full_t h r')
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
(z == Spec.Ed25519.(
let exp_d = point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a') in
point_equal exp_d (F51.point_eval h0 r'))))
let verify_all_valid_hb sb hb a' r' =
push_frame ();
let exp_d = create 20ul (u64 0) in
PM.point_negate_mul_double_g_vartime exp_d sb hb a';
let b = Hacl.Impl.Ed25519.PointEqual.point_equal exp_d r' in
let h0 = ST.get () in
Spec.Ed25519.Lemmas.point_equal_lemma
(F51.point_eval h0 exp_d)
(Spec.Ed25519.point_negate_mul_double_g (as_seq h0 sb) (as_seq h0 hb) (F51.point_eval h0 a'))
(F51.point_eval h0 r');
pop_frame ();
b
inline_for_extraction noextract
val verify_sb: sb:lbuffer uint8 32ul -> Stack bool
(requires fun h -> live h sb)
(ensures fun h0 b h1 -> modifies0 h0 h1 /\
(b <==> (BSeq.nat_from_bytes_le (as_seq h0 sb) >= Spec.Ed25519.q)))
let verify_sb sb =
push_frame ();
let tmp = create 5ul (u64 0) in
Hacl.Impl.Load56.load_32_bytes tmp sb;
let b = Hacl.Impl.Ed25519.PointEqual.gte_q tmp in
pop_frame ();
b
inline_for_extraction noextract
val verify_valid_pk_rs:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul
-> a':point
-> r':point ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature /\ live h a' /\ live h r' /\
(Some? (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ point_inv_full_t h a' /\
(F51.point_eval h a' == Some?.v (Spec.Ed25519.point_decompress (as_seq h public_key))) /\
(Some? (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul)))) /\ point_inv_full_t h r' /\
(F51.point_eval h r' == Some?.v (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul)))))
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature)) | false | false | Hacl.Impl.Ed25519.Verify.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val verify_valid_pk_rs:
public_key:lbuffer uint8 32ul
-> msg_len:size_t
-> msg:lbuffer uint8 msg_len
-> signature:lbuffer uint8 64ul
-> a':point
-> r':point ->
Stack bool
(requires fun h ->
live h public_key /\ live h msg /\ live h signature /\ live h a' /\ live h r' /\
(Some? (Spec.Ed25519.point_decompress (as_seq h public_key))) /\ point_inv_full_t h a' /\
(F51.point_eval h a' == Some?.v (Spec.Ed25519.point_decompress (as_seq h public_key))) /\
(Some? (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul)))) /\ point_inv_full_t h r' /\
(F51.point_eval h r' == Some?.v (Spec.Ed25519.point_decompress (as_seq h (gsub signature 0ul 32ul)))))
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
z == Spec.Ed25519.verify (as_seq h0 public_key) (as_seq h0 msg) (as_seq h0 signature)) | [] | Hacl.Impl.Ed25519.Verify.verify_valid_pk_rs | {
"file_name": "code/ed25519/Hacl.Impl.Ed25519.Verify.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
public_key: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
msg_len: Lib.IntTypes.size_t ->
msg: Lib.Buffer.lbuffer Lib.IntTypes.uint8 msg_len ->
signature: Lib.Buffer.lbuffer Lib.IntTypes.uint8 64ul ->
a': Hacl.Bignum25519.point ->
r': Hacl.Bignum25519.point
-> FStar.HyperStack.ST.Stack Prims.bool | {
"end_col": 5,
"end_line": 94,
"start_col": 2,
"start_line": 82
} |
FStar.Tactics.Effect.Tac | val pp_sigmaTable: Prims.unit -> Tactics.Tac unit | [
{
"abbrev": true,
"full_module": "Spec.Blake2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pp_sigmaTable () : Tactics.Tac unit =
Tactics.norm [delta_only [`%Spec.list_sigma]]; Tactics.trefl () | val pp_sigmaTable: Prims.unit -> Tactics.Tac unit
let pp_sigmaTable () : Tactics.Tac unit = | true | null | false | Tactics.norm [delta_only [`%Spec.list_sigma]];
Tactics.trefl () | {
"checked_file": "Hacl.Impl.Blake2.Constants.fst.checked",
"dependencies": [
"Spec.Blake2.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Constants.fst"
} | [] | [
"Prims.unit",
"FStar.Tactics.V1.Derived.trefl",
"FStar.Tactics.V1.Builtins.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta_only",
"Prims.string",
"Prims.Nil"
] | [] | module Hacl.Impl.Blake2.Constants
open FStar.Mul
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.LoopCombinators
module ST = FStar.HyperStack.ST
module Seq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Spec = Spec.Blake2
/// We need to unfold manually the definition of the sigma table. This definition
/// was not declared as `inline_for_extraction` because otherwise it creates a lot
/// of work for the normalizer during the KaRaMeL extraction (which also explores
/// the ghost code, including the content of the assertions). However, we can't do
/// that by inserting manual calls to `norm` inside the code, because it blocks
/// the normalization performed by KaRaMeL, and we can't normalize as much as we
/// want because of the interface abstractions. The solution is to use post-processing.
noextract | false | false | Hacl.Impl.Blake2.Constants.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pp_sigmaTable: Prims.unit -> Tactics.Tac unit | [] | Hacl.Impl.Blake2.Constants.pp_sigmaTable | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Constants.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | _: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit | {
"end_col": 65,
"end_line": 25,
"start_col": 2,
"start_line": 25
} |
Prims.Tot | val ivTable_B:(x:
glbuffer (Spec.pub_word_t Spec.Blake2B) 8ul
{witnessed x (Spec.ivTable Spec.Blake2B) /\ recallable x}) | [
{
"abbrev": true,
"full_module": "Spec.Blake2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ivTable_B: (x:glbuffer (Spec.pub_word_t Spec.Blake2B) 8ul{witnessed x (Spec.ivTable Spec.Blake2B) /\ recallable x}) =
createL_global Spec.list_iv_B | val ivTable_B:(x:
glbuffer (Spec.pub_word_t Spec.Blake2B) 8ul
{witnessed x (Spec.ivTable Spec.Blake2B) /\ recallable x})
let ivTable_B:(x:
glbuffer (Spec.pub_word_t Spec.Blake2B) 8ul
{witnessed x (Spec.ivTable Spec.Blake2B) /\ recallable x}) = | false | null | false | createL_global Spec.list_iv_B | {
"checked_file": "Hacl.Impl.Blake2.Constants.fst.checked",
"dependencies": [
"Spec.Blake2.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Constants.fst"
} | [
"total"
] | [
"Lib.Buffer.createL_global",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.PUB",
"Spec.Blake2.list_iv_B",
"Lib.Buffer.glbuffer",
"Lib.IntTypes.size",
"FStar.Pervasives.normalize_term",
"Lib.IntTypes.size_nat",
"FStar.List.Tot.Base.length"
] | [] | module Hacl.Impl.Blake2.Constants
open FStar.Mul
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.LoopCombinators
module ST = FStar.HyperStack.ST
module Seq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Spec = Spec.Blake2
/// We need to unfold manually the definition of the sigma table. This definition
/// was not declared as `inline_for_extraction` because otherwise it creates a lot
/// of work for the normalizer during the KaRaMeL extraction (which also explores
/// the ghost code, including the content of the assertions). However, we can't do
/// that by inserting manual calls to `norm` inside the code, because it blocks
/// the normalization performed by KaRaMeL, and we can't normalize as much as we
/// want because of the interface abstractions. The solution is to use post-processing.
noextract
let pp_sigmaTable () : Tactics.Tac unit =
Tactics.norm [delta_only [`%Spec.list_sigma]]; Tactics.trefl ()
[@(Tactics.postprocess_with pp_sigmaTable)]
let sigmaTable : x:glbuffer Spec.sigma_elt_t 160ul{witnessed x Spec.sigmaTable /\ recallable x} =
createL_global Spec.list_sigma
let ivTable_S: (x:glbuffer (Spec.pub_word_t Spec.Blake2S) 8ul{witnessed x (Spec.ivTable Spec.Blake2S) /\ recallable x}) =
createL_global Spec.list_iv_S | false | false | Hacl.Impl.Blake2.Constants.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ivTable_B:(x:
glbuffer (Spec.pub_word_t Spec.Blake2B) 8ul
{witnessed x (Spec.ivTable Spec.Blake2B) /\ recallable x}) | [] | Hacl.Impl.Blake2.Constants.ivTable_B | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Constants.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x:
(c:
Lib.Buffer.lbuffer_t Lib.Buffer.CONST
(Spec.Blake2.pub_word_t Spec.Blake2.Blake2B)
(FStar.UInt32.uint_to_t 8 <: FStar.UInt32.t)
{LowStar.ConstBuffer.qual_of c == LowStar.ConstBuffer.IMMUTABLE})
{Lib.Buffer.witnessed x (Spec.Blake2.ivTable Spec.Blake2.Blake2B) /\ Lib.Buffer.recallable x} | {
"end_col": 31,
"end_line": 35,
"start_col": 2,
"start_line": 35
} |
Prims.Tot | val ivTable_S:(x:
glbuffer (Spec.pub_word_t Spec.Blake2S) 8ul
{witnessed x (Spec.ivTable Spec.Blake2S) /\ recallable x}) | [
{
"abbrev": true,
"full_module": "Spec.Blake2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let ivTable_S: (x:glbuffer (Spec.pub_word_t Spec.Blake2S) 8ul{witnessed x (Spec.ivTable Spec.Blake2S) /\ recallable x}) =
createL_global Spec.list_iv_S | val ivTable_S:(x:
glbuffer (Spec.pub_word_t Spec.Blake2S) 8ul
{witnessed x (Spec.ivTable Spec.Blake2S) /\ recallable x})
let ivTable_S:(x:
glbuffer (Spec.pub_word_t Spec.Blake2S) 8ul
{witnessed x (Spec.ivTable Spec.Blake2S) /\ recallable x}) = | false | null | false | createL_global Spec.list_iv_S | {
"checked_file": "Hacl.Impl.Blake2.Constants.fst.checked",
"dependencies": [
"Spec.Blake2.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Constants.fst"
} | [
"total"
] | [
"Lib.Buffer.createL_global",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Spec.Blake2.list_iv_S",
"Lib.Buffer.glbuffer",
"Lib.IntTypes.size",
"FStar.Pervasives.normalize_term",
"Lib.IntTypes.size_nat",
"FStar.List.Tot.Base.length"
] | [] | module Hacl.Impl.Blake2.Constants
open FStar.Mul
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.LoopCombinators
module ST = FStar.HyperStack.ST
module Seq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Spec = Spec.Blake2
/// We need to unfold manually the definition of the sigma table. This definition
/// was not declared as `inline_for_extraction` because otherwise it creates a lot
/// of work for the normalizer during the KaRaMeL extraction (which also explores
/// the ghost code, including the content of the assertions). However, we can't do
/// that by inserting manual calls to `norm` inside the code, because it blocks
/// the normalization performed by KaRaMeL, and we can't normalize as much as we
/// want because of the interface abstractions. The solution is to use post-processing.
noextract
let pp_sigmaTable () : Tactics.Tac unit =
Tactics.norm [delta_only [`%Spec.list_sigma]]; Tactics.trefl ()
[@(Tactics.postprocess_with pp_sigmaTable)]
let sigmaTable : x:glbuffer Spec.sigma_elt_t 160ul{witnessed x Spec.sigmaTable /\ recallable x} =
createL_global Spec.list_sigma | false | false | Hacl.Impl.Blake2.Constants.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val ivTable_S:(x:
glbuffer (Spec.pub_word_t Spec.Blake2S) 8ul
{witnessed x (Spec.ivTable Spec.Blake2S) /\ recallable x}) | [] | Hacl.Impl.Blake2.Constants.ivTable_S | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Constants.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x:
(c:
Lib.Buffer.lbuffer_t Lib.Buffer.CONST
(Spec.Blake2.pub_word_t Spec.Blake2.Blake2S)
(FStar.UInt32.uint_to_t 8 <: FStar.UInt32.t)
{LowStar.ConstBuffer.qual_of c == LowStar.ConstBuffer.IMMUTABLE})
{Lib.Buffer.witnessed x (Spec.Blake2.ivTable Spec.Blake2.Blake2S) /\ Lib.Buffer.recallable x} | {
"end_col": 31,
"end_line": 32,
"start_col": 2,
"start_line": 32
} |
Prims.Tot | val rTable_B:x: glbuffer (rotval U64) 4ul {witnessed x (Spec.rTable Spec.Blake2B) /\ recallable x} | [
{
"abbrev": true,
"full_module": "Spec.Blake2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let rTable_B : x:glbuffer (rotval U64) 4ul{witnessed x (Spec.rTable Spec.Blake2B) /\ recallable x} =
createL_global Spec.rTable_list_B | val rTable_B:x: glbuffer (rotval U64) 4ul {witnessed x (Spec.rTable Spec.Blake2B) /\ recallable x}
let rTable_B:x: glbuffer (rotval U64) 4ul {witnessed x (Spec.rTable Spec.Blake2B) /\ recallable x} = | false | null | false | createL_global Spec.rTable_list_B | {
"checked_file": "Hacl.Impl.Blake2.Constants.fst.checked",
"dependencies": [
"Spec.Blake2.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Constants.fst"
} | [
"total"
] | [
"Lib.Buffer.createL_global",
"Lib.IntTypes.rotval",
"Lib.IntTypes.U64",
"Spec.Blake2.rTable_list_B",
"Lib.Buffer.glbuffer",
"Lib.IntTypes.size",
"FStar.Pervasives.normalize_term",
"Lib.IntTypes.size_nat",
"FStar.List.Tot.Base.length"
] | [] | module Hacl.Impl.Blake2.Constants
open FStar.Mul
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.LoopCombinators
module ST = FStar.HyperStack.ST
module Seq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Spec = Spec.Blake2
/// We need to unfold manually the definition of the sigma table. This definition
/// was not declared as `inline_for_extraction` because otherwise it creates a lot
/// of work for the normalizer during the KaRaMeL extraction (which also explores
/// the ghost code, including the content of the assertions). However, we can't do
/// that by inserting manual calls to `norm` inside the code, because it blocks
/// the normalization performed by KaRaMeL, and we can't normalize as much as we
/// want because of the interface abstractions. The solution is to use post-processing.
noextract
let pp_sigmaTable () : Tactics.Tac unit =
Tactics.norm [delta_only [`%Spec.list_sigma]]; Tactics.trefl ()
[@(Tactics.postprocess_with pp_sigmaTable)]
let sigmaTable : x:glbuffer Spec.sigma_elt_t 160ul{witnessed x Spec.sigmaTable /\ recallable x} =
createL_global Spec.list_sigma
let ivTable_S: (x:glbuffer (Spec.pub_word_t Spec.Blake2S) 8ul{witnessed x (Spec.ivTable Spec.Blake2S) /\ recallable x}) =
createL_global Spec.list_iv_S
let ivTable_B: (x:glbuffer (Spec.pub_word_t Spec.Blake2B) 8ul{witnessed x (Spec.ivTable Spec.Blake2B) /\ recallable x}) =
createL_global Spec.list_iv_B | false | false | Hacl.Impl.Blake2.Constants.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val rTable_B:x: glbuffer (rotval U64) 4ul {witnessed x (Spec.rTable Spec.Blake2B) /\ recallable x} | [] | Hacl.Impl.Blake2.Constants.rTable_B | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Constants.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x:
(c:
Lib.Buffer.lbuffer_t Lib.Buffer.CONST
(Lib.IntTypes.rotval Lib.IntTypes.U64)
(FStar.UInt32.uint_to_t 4 <: FStar.UInt32.t)
{LowStar.ConstBuffer.qual_of c == LowStar.ConstBuffer.IMMUTABLE})
{Lib.Buffer.witnessed x (Spec.Blake2.rTable Spec.Blake2.Blake2B) /\ Lib.Buffer.recallable x} | {
"end_col": 35,
"end_line": 38,
"start_col": 2,
"start_line": 38
} |
Prims.Tot | val sigmaTable:x: glbuffer Spec.sigma_elt_t 160ul {witnessed x Spec.sigmaTable /\ recallable x} | [
{
"abbrev": true,
"full_module": "Spec.Blake2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.LoopCombinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.ByteBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Blake2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sigmaTable : x:glbuffer Spec.sigma_elt_t 160ul{witnessed x Spec.sigmaTable /\ recallable x} =
createL_global Spec.list_sigma | val sigmaTable:x: glbuffer Spec.sigma_elt_t 160ul {witnessed x Spec.sigmaTable /\ recallable x}
let sigmaTable:x: glbuffer Spec.sigma_elt_t 160ul {witnessed x Spec.sigmaTable /\ recallable x} = | false | null | false | createL_global Spec.list_sigma | {
"checked_file": "Hacl.Impl.Blake2.Constants.fst.checked",
"dependencies": [
"Spec.Blake2.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Blake2.Constants.fst"
} | [
"total"
] | [
"Lib.Buffer.createL_global",
"Spec.Blake2.sigma_elt_t",
"Prims.Cons",
"Lib.IntTypes.size",
"Prims.Nil"
] | [] | module Hacl.Impl.Blake2.Constants
open FStar.Mul
open FStar.HyperStack
open FStar.HyperStack.ST
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Lib.LoopCombinators
module ST = FStar.HyperStack.ST
module Seq = Lib.Sequence
module Loops = Lib.LoopCombinators
module Spec = Spec.Blake2
/// We need to unfold manually the definition of the sigma table. This definition
/// was not declared as `inline_for_extraction` because otherwise it creates a lot
/// of work for the normalizer during the KaRaMeL extraction (which also explores
/// the ghost code, including the content of the assertions). However, we can't do
/// that by inserting manual calls to `norm` inside the code, because it blocks
/// the normalization performed by KaRaMeL, and we can't normalize as much as we
/// want because of the interface abstractions. The solution is to use post-processing.
noextract
let pp_sigmaTable () : Tactics.Tac unit =
Tactics.norm [delta_only [`%Spec.list_sigma]]; Tactics.trefl ()
[@(Tactics.postprocess_with pp_sigmaTable)] | false | false | Hacl.Impl.Blake2.Constants.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sigmaTable:x: glbuffer Spec.sigma_elt_t 160ul {witnessed x Spec.sigmaTable /\ recallable x} | [] | Hacl.Impl.Blake2.Constants.sigmaTable | {
"file_name": "code/blake2/Hacl.Impl.Blake2.Constants.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | x:
(c:
Lib.Buffer.lbuffer_t Lib.Buffer.CONST
Spec.Blake2.sigma_elt_t
(FStar.UInt32.uint_to_t 160 <: FStar.UInt32.t)
{LowStar.ConstBuffer.qual_of c == LowStar.ConstBuffer.IMMUTABLE})
{Lib.Buffer.witnessed x Spec.Blake2.sigmaTable /\ Lib.Buffer.recallable x} | {
"end_col": 32,
"end_line": 29,
"start_col": 2,
"start_line": 29
} |
Prims.Tot | val sealBase: sealBase_st cs True | [
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.AEAD",
"short_module": "IAEAD"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.Hash",
"short_module": "IHash"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.HKDF",
"short_module": "IHK"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.DH",
"short_module": "IDH"
},
{
"abbrev": false,
"full_module": "Hacl.Meta.HPKE",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let sealBase = hpke_sealBase_higher #cs True IAEAD.aead_encrypt_cp32 setupBaseS | val sealBase: sealBase_st cs True
let sealBase = | false | null | false | hpke_sealBase_higher #cs True IAEAD.aead_encrypt_cp32 setupBaseS | {
"checked_file": "Hacl.HPKE.P256_CP32_SHA256.fst.checked",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.HPKE.Interface.HKDF.fst.checked",
"Hacl.HPKE.Interface.Hash.fst.checked",
"Hacl.HPKE.Interface.DH.fst.checked",
"Hacl.HPKE.Interface.AEAD.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.HPKE.P256_CP32_SHA256.fst"
} | [
"total"
] | [
"Hacl.Meta.HPKE.hpke_sealBase_higher",
"Hacl.HPKE.P256_CP32_SHA256.cs",
"Prims.l_True",
"Hacl.HPKE.Interface.AEAD.aead_encrypt_cp32",
"Hacl.HPKE.P256_CP32_SHA256.setupBaseS"
] | [] | module Hacl.HPKE.P256_CP32_SHA256
open Hacl.Meta.HPKE
module IDH = Hacl.HPKE.Interface.DH
module IHK = Hacl.HPKE.Interface.HKDF
module IHash = Hacl.HPKE.Interface.Hash
module IAEAD = Hacl.HPKE.Interface.AEAD
friend Hacl.Meta.HPKE
#set-options "--fuel 0 --ifuel 0"
let setupBaseS = hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256
let setupBaseR = hpke_setupBaseR_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256 | false | true | Hacl.HPKE.P256_CP32_SHA256.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val sealBase: sealBase_st cs True | [] | Hacl.HPKE.P256_CP32_SHA256.sealBase | {
"file_name": "code/hpke/Hacl.HPKE.P256_CP32_SHA256.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.HPKE.sealBase_st Hacl.HPKE.P256_CP32_SHA256.cs Prims.l_True | {
"end_col": 79,
"end_line": 18,
"start_col": 15,
"start_line": 18
} |
Prims.Tot | val openBase: openBase_st cs True | [
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.AEAD",
"short_module": "IAEAD"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.Hash",
"short_module": "IHash"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.HKDF",
"short_module": "IHK"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.DH",
"short_module": "IDH"
},
{
"abbrev": false,
"full_module": "Hacl.Meta.HPKE",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let openBase = hpke_openBase_higher #cs True IAEAD.aead_decrypt_cp32 setupBaseR | val openBase: openBase_st cs True
let openBase = | false | null | false | hpke_openBase_higher #cs True IAEAD.aead_decrypt_cp32 setupBaseR | {
"checked_file": "Hacl.HPKE.P256_CP32_SHA256.fst.checked",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.HPKE.Interface.HKDF.fst.checked",
"Hacl.HPKE.Interface.Hash.fst.checked",
"Hacl.HPKE.Interface.DH.fst.checked",
"Hacl.HPKE.Interface.AEAD.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.HPKE.P256_CP32_SHA256.fst"
} | [
"total"
] | [
"Hacl.Meta.HPKE.hpke_openBase_higher",
"Hacl.HPKE.P256_CP32_SHA256.cs",
"Prims.l_True",
"Hacl.HPKE.Interface.AEAD.aead_decrypt_cp32",
"Hacl.HPKE.P256_CP32_SHA256.setupBaseR"
] | [] | module Hacl.HPKE.P256_CP32_SHA256
open Hacl.Meta.HPKE
module IDH = Hacl.HPKE.Interface.DH
module IHK = Hacl.HPKE.Interface.HKDF
module IHash = Hacl.HPKE.Interface.Hash
module IAEAD = Hacl.HPKE.Interface.AEAD
friend Hacl.Meta.HPKE
#set-options "--fuel 0 --ifuel 0"
let setupBaseS = hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256
let setupBaseR = hpke_setupBaseR_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256
let sealBase = hpke_sealBase_higher #cs True IAEAD.aead_encrypt_cp32 setupBaseS | false | true | Hacl.HPKE.P256_CP32_SHA256.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val openBase: openBase_st cs True | [] | Hacl.HPKE.P256_CP32_SHA256.openBase | {
"file_name": "code/hpke/Hacl.HPKE.P256_CP32_SHA256.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.HPKE.openBase_st Hacl.HPKE.P256_CP32_SHA256.cs Prims.l_True | {
"end_col": 79,
"end_line": 20,
"start_col": 15,
"start_line": 20
} |
Prims.Tot | val setupBaseS: setupBaseS_st cs True | [
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.AEAD",
"short_module": "IAEAD"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.Hash",
"short_module": "IHash"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.HKDF",
"short_module": "IHK"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.DH",
"short_module": "IDH"
},
{
"abbrev": false,
"full_module": "Hacl.Meta.HPKE",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let setupBaseS = hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256 | val setupBaseS: setupBaseS_st cs True
let setupBaseS = | false | null | false | hpke_setupBaseS_higher #cs
True
IHK.hkdf_expand256
IHK.hkdf_extract256
IDH.secret_to_public_p256
IDH.dh_p256
IHK.hkdf_expand256
IHK.hkdf_extract256 | {
"checked_file": "Hacl.HPKE.P256_CP32_SHA256.fst.checked",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.HPKE.Interface.HKDF.fst.checked",
"Hacl.HPKE.Interface.Hash.fst.checked",
"Hacl.HPKE.Interface.DH.fst.checked",
"Hacl.HPKE.Interface.AEAD.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.HPKE.P256_CP32_SHA256.fst"
} | [
"total"
] | [
"Hacl.Meta.HPKE.hpke_setupBaseS_higher",
"Hacl.HPKE.P256_CP32_SHA256.cs",
"Prims.l_True",
"Hacl.HPKE.Interface.HKDF.hkdf_expand256",
"Hacl.HPKE.Interface.HKDF.hkdf_extract256",
"Hacl.HPKE.Interface.DH.secret_to_public_p256",
"Hacl.HPKE.Interface.DH.dh_p256"
] | [] | module Hacl.HPKE.P256_CP32_SHA256
open Hacl.Meta.HPKE
module IDH = Hacl.HPKE.Interface.DH
module IHK = Hacl.HPKE.Interface.HKDF
module IHash = Hacl.HPKE.Interface.Hash
module IAEAD = Hacl.HPKE.Interface.AEAD
friend Hacl.Meta.HPKE
#set-options "--fuel 0 --ifuel 0" | false | true | Hacl.HPKE.P256_CP32_SHA256.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val setupBaseS: setupBaseS_st cs True | [] | Hacl.HPKE.P256_CP32_SHA256.setupBaseS | {
"file_name": "code/hpke/Hacl.HPKE.P256_CP32_SHA256.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.HPKE.setupBaseS_st Hacl.HPKE.P256_CP32_SHA256.cs Prims.l_True | {
"end_col": 164,
"end_line": 14,
"start_col": 17,
"start_line": 14
} |
Prims.Tot | val setupBaseR: setupBaseR_st cs True | [
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.AEAD",
"short_module": "IAEAD"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.Hash",
"short_module": "IHash"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.HKDF",
"short_module": "IHK"
},
{
"abbrev": true,
"full_module": "Hacl.HPKE.Interface.DH",
"short_module": "IDH"
},
{
"abbrev": false,
"full_module": "Hacl.Meta.HPKE",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Hash"
},
{
"abbrev": true,
"full_module": "Spec.Agile.AEAD",
"short_module": "AEAD"
},
{
"abbrev": true,
"full_module": "Spec.Agile.DH",
"short_module": "DH"
},
{
"abbrev": true,
"full_module": "Spec.Agile.HPKE",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.HPKE",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let setupBaseR = hpke_setupBaseR_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256 | val setupBaseR: setupBaseR_st cs True
let setupBaseR = | false | null | false | hpke_setupBaseR_higher #cs
True
IHK.hkdf_expand256
IHK.hkdf_extract256
IDH.dh_p256
IHK.hkdf_expand256
IHK.hkdf_extract256
IDH.secret_to_public_p256 | {
"checked_file": "Hacl.HPKE.P256_CP32_SHA256.fst.checked",
"dependencies": [
"prims.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.Meta.HPKE.fst.checked",
"Hacl.HPKE.Interface.HKDF.fst.checked",
"Hacl.HPKE.Interface.Hash.fst.checked",
"Hacl.HPKE.Interface.DH.fst.checked",
"Hacl.HPKE.Interface.AEAD.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.HPKE.P256_CP32_SHA256.fst"
} | [
"total"
] | [
"Hacl.Meta.HPKE.hpke_setupBaseR_higher",
"Hacl.HPKE.P256_CP32_SHA256.cs",
"Prims.l_True",
"Hacl.HPKE.Interface.HKDF.hkdf_expand256",
"Hacl.HPKE.Interface.HKDF.hkdf_extract256",
"Hacl.HPKE.Interface.DH.dh_p256",
"Hacl.HPKE.Interface.DH.secret_to_public_p256"
] | [] | module Hacl.HPKE.P256_CP32_SHA256
open Hacl.Meta.HPKE
module IDH = Hacl.HPKE.Interface.DH
module IHK = Hacl.HPKE.Interface.HKDF
module IHash = Hacl.HPKE.Interface.Hash
module IAEAD = Hacl.HPKE.Interface.AEAD
friend Hacl.Meta.HPKE
#set-options "--fuel 0 --ifuel 0"
let setupBaseS = hpke_setupBaseS_higher #cs True IHK.hkdf_expand256 IHK.hkdf_extract256 IDH.secret_to_public_p256 IDH.dh_p256 IHK.hkdf_expand256 IHK.hkdf_extract256 | false | true | Hacl.HPKE.P256_CP32_SHA256.fst | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val setupBaseR: setupBaseR_st cs True | [] | Hacl.HPKE.P256_CP32_SHA256.setupBaseR | {
"file_name": "code/hpke/Hacl.HPKE.P256_CP32_SHA256.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Impl.HPKE.setupBaseR_st Hacl.HPKE.P256_CP32_SHA256.cs Prims.l_True | {
"end_col": 164,
"end_line": 16,
"start_col": 17,
"start_line": 16
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.X64.Decls",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.PossiblyMonad",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.Machine_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Transformers",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let equiv_states (s1 s2:va_state) =
let open Vale.X64.State in
s1.vs_ok == s2.vs_ok /\
Vale.X64.Regs.equal s1.vs_regs s2.vs_regs /\
Vale.X64.Flags.sel fCarry s1.vs_flags == Vale.X64.Flags.sel fCarry s2.vs_flags /\
Vale.X64.Flags.sel fOverflow s1.vs_flags == Vale.X64.Flags.sel fOverflow s2.vs_flags /\
s1.vs_heap == s2.vs_heap /\
s1.vs_stack == s2.vs_stack /\
s1.vs_stackTaint == s2.vs_stackTaint | let equiv_states (s1 s2: va_state) = | false | null | false | let open Vale.X64.State in
s1.vs_ok == s2.vs_ok /\ Vale.X64.Regs.equal s1.vs_regs s2.vs_regs /\
Vale.X64.Flags.sel fCarry s1.vs_flags == Vale.X64.Flags.sel fCarry s2.vs_flags /\
Vale.X64.Flags.sel fOverflow s1.vs_flags == Vale.X64.Flags.sel fOverflow s2.vs_flags /\
s1.vs_heap == s2.vs_heap /\ s1.vs_stack == s2.vs_stack /\ s1.vs_stackTaint == s2.vs_stackTaint | {
"checked_file": "Vale.Transformers.Common.fsti.checked",
"dependencies": [
"Vale.X64.State.fsti.checked",
"Vale.X64.Regs.fsti.checked",
"Vale.X64.Machine_s.fst.checked",
"Vale.X64.Flags.fsti.checked",
"Vale.X64.Decls.fsti.checked",
"Vale.Def.PossiblyMonad.fst.checked",
"prims.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Transformers.Common.fsti"
} | [
"total"
] | [
"Vale.X64.Decls.va_state",
"Prims.l_and",
"Prims.eq2",
"Prims.bool",
"Vale.X64.State.__proj__Mkvale_state__item__vs_ok",
"Vale.X64.Regs.equal",
"Vale.X64.State.__proj__Mkvale_state__item__vs_regs",
"Vale.X64.Flags.flag_val_t",
"Vale.X64.Flags.sel",
"Vale.X64.Machine_s.fCarry",
"Vale.X64.State.__proj__Mkvale_state__item__vs_flags",
"Vale.X64.Machine_s.fOverflow",
"Vale.X64.Memory.vale_full_heap",
"Vale.X64.State.__proj__Mkvale_state__item__vs_heap",
"Vale.X64.Stack_i.vale_stack",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stack",
"Vale.X64.Memory.memtaint",
"Vale.X64.State.__proj__Mkvale_state__item__vs_stackTaint",
"Prims.logical"
] | [] | module Vale.Transformers.Common
open Vale.X64.Machine_s
open Vale.Def.PossiblyMonad
open Vale.X64.Decls
/// Common definitions amongst transformations. | false | true | Vale.Transformers.Common.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val equiv_states : s1: Vale.X64.Decls.va_state -> s2: Vale.X64.Decls.va_state -> Prims.logical | [] | Vale.Transformers.Common.equiv_states | {
"file_name": "vale/code/lib/transformers/Vale.Transformers.Common.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | s1: Vale.X64.Decls.va_state -> s2: Vale.X64.Decls.va_state -> Prims.logical | {
"end_col": 38,
"end_line": 17,
"start_col": 2,
"start_line": 10
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let table_len_t (len:size_t{v len > 0}) =
table_len:size_t{v table_len * v len <= max_size_t} | let table_len_t (len: size_t{v len > 0}) = | false | null | false | table_len: size_t{v table_len * v len <= max_size_t} | {
"checked_file": "Hacl.Impl.Exponentiation.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Exponentiation.fsti"
} | [
"total"
] | [
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module PT = Hacl.Impl.PrecompTable
include Hacl.Impl.Exponentiation.Definitions
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
// This function computes `a^b` using a binary right-to-left method
// It takes variable time to compute the result
inline_for_extraction noextract
val lexp_rl_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h ctx /\
disjoint a res /\ disjoint b res /\ disjoint a b /\
disjoint ctx a /\ disjoint ctx res /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a))
(ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\
k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_rl #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b))
// This function computes `a^b` using Montgomery's ladder (a binary method)
// It takes constant time to compute the result
inline_for_extraction noextract
val lexp_mont_ladder_swap_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h ctx /\
disjoint a res /\ disjoint b res /\ disjoint a b /\
disjoint ctx a /\ disjoint ctx res /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a))
(ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\
k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_mont_ladder_swap #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b))
// This function computes `a^(2^b)` and writes the result in `res`
inline_for_extraction noextract
val lexp_pow2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h res /\ live h ctx /\ live h a /\
disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b))
// This function computes `a^(2^b)` and writes the result in `a`
inline_for_extraction noextract
val lexp_pow2_in_place:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t ->
Stack unit
(requires fun h ->
live h a /\ live h ctx /\ disjoint a ctx /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\
k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b))
// Fixed-window method using a precomputed table
//----------------------------------------------
inline_for_extraction noextract
let size_window_t (a_t:inttype_a) (len:size_t{v len > 0}) =
l:size_t{0 < v l /\ v l < bits a_t /\ v l < 32 /\ pow2 (v l) * v len <= max_size_t}
inline_for_extraction noextract | false | false | Hacl.Impl.Exponentiation.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val table_len_t : len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Type0 | [] | Hacl.Impl.Exponentiation.table_len_t | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} -> Type0 | {
"end_col": 53,
"end_line": 124,
"start_col": 2,
"start_line": 124
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let size_window_t (a_t:inttype_a) (len:size_t{v len > 0}) =
l:size_t{0 < v l /\ v l < bits a_t /\ v l < 32 /\ pow2 (v l) * v len <= max_size_t} | let size_window_t (a_t: inttype_a) (len: size_t{v len > 0}) = | false | null | false | l: size_t{0 < v l /\ v l < bits a_t /\ v l < 32 /\ pow2 (v l) * v len <= max_size_t} | {
"checked_file": "Hacl.Impl.Exponentiation.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Exponentiation.fsti"
} | [
"total"
] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.l_and",
"Prims.op_LessThan",
"Lib.IntTypes.bits",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Prims.pow2",
"Lib.IntTypes.max_size_t"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module PT = Hacl.Impl.PrecompTable
include Hacl.Impl.Exponentiation.Definitions
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
// This function computes `a^b` using a binary right-to-left method
// It takes variable time to compute the result
inline_for_extraction noextract
val lexp_rl_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h ctx /\
disjoint a res /\ disjoint b res /\ disjoint a b /\
disjoint ctx a /\ disjoint ctx res /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a))
(ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\
k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_rl #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b))
// This function computes `a^b` using Montgomery's ladder (a binary method)
// It takes constant time to compute the result
inline_for_extraction noextract
val lexp_mont_ladder_swap_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h ctx /\
disjoint a res /\ disjoint b res /\ disjoint a b /\
disjoint ctx a /\ disjoint ctx res /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a))
(ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\
k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_mont_ladder_swap #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b))
// This function computes `a^(2^b)` and writes the result in `res`
inline_for_extraction noextract
val lexp_pow2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h res /\ live h ctx /\ live h a /\
disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b))
// This function computes `a^(2^b)` and writes the result in `a`
inline_for_extraction noextract
val lexp_pow2_in_place:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t ->
Stack unit
(requires fun h ->
live h a /\ live h ctx /\ disjoint a ctx /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\
k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b))
// Fixed-window method using a precomputed table
//----------------------------------------------
inline_for_extraction noextract | false | false | Hacl.Impl.Exponentiation.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val size_window_t : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0}
-> Type0 | [] | Hacl.Impl.Exponentiation.size_window_t | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0}
-> Type0 | {
"end_col": 85,
"end_line": 120,
"start_col": 2,
"start_line": 120
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Hacl.Impl.Exponentiation.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Impl.PrecompTable",
"short_module": "PT"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "Lib.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let table_inv_t (a_t:inttype_a) (len:size_t{v len > 0}) (table_len:table_len_t len) =
a:LSeq.lseq (uint_t a_t SEC) (v len)
-> table:LSeq.lseq (uint_t a_t SEC) (v (table_len *! len)) -> GTot Type0 | let table_inv_t (a_t: inttype_a) (len: size_t{v len > 0}) (table_len: table_len_t len) = | false | null | false | a: LSeq.lseq (uint_t a_t SEC) (v len) -> table: LSeq.lseq (uint_t a_t SEC) (v (table_len *! len))
-> GTot Type0 | {
"checked_file": "Hacl.Impl.Exponentiation.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Exponentiation.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.PrecompTable.fsti.checked",
"Hacl.Impl.Exponentiation.Definitions.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.Exponentiation.fsti"
} | [
"total"
] | [
"Hacl.Impl.Exponentiation.Definitions.inttype_a",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Exponentiation.table_len_t",
"Lib.Sequence.lseq",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Star_Bang"
] | [] | module Hacl.Impl.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module S = Lib.Exponentiation
module BD = Hacl.Bignum.Definitions
module PT = Hacl.Impl.PrecompTable
include Hacl.Impl.Exponentiation.Definitions
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
// This function computes `a^b` using a binary right-to-left method
// It takes variable time to compute the result
inline_for_extraction noextract
val lexp_rl_vartime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h ctx /\
disjoint a res /\ disjoint b res /\ disjoint a b /\
disjoint ctx a /\ disjoint ctx res /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a))
(ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\
k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_rl #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b))
// This function computes `a^b` using Montgomery's ladder (a binary method)
// It takes constant time to compute the result
inline_for_extraction noextract
val lexp_mont_ladder_swap_consttime:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> bLen:size_t
-> bBits:size_t{(v bBits - 1) / bits a_t < v bLen}
-> b:lbuffer (uint_t a_t SEC) bLen
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h ctx /\
disjoint a res /\ disjoint b res /\ disjoint a b /\
disjoint ctx a /\ disjoint ctx res /\
BD.bn_v h b < pow2 (v bBits) /\
k.to.linv_ctx (as_seq h ctx) /\
k.to.linv (as_seq h a))
(ensures fun h0 _ h1 -> modifies (loc a |+| loc res) h0 h1 /\
k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) ==
S.exp_mont_ladder_swap #k.to.a_spec k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v bBits) (BD.bn_v h0 b))
// This function computes `a^(2^b)` and writes the result in `res`
inline_for_extraction noextract
val lexp_pow2:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t
-> res:lbuffer (uint_t a_t SEC) len ->
Stack unit
(requires fun h ->
live h res /\ live h ctx /\ live h a /\
disjoint res ctx /\ disjoint a ctx /\ disjoint a res /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\ k.to.linv (as_seq h1 res) /\
k.to.refl (as_seq h1 res) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b))
// This function computes `a^(2^b)` and writes the result in `a`
inline_for_extraction noextract
val lexp_pow2_in_place:
#a_t:inttype_a
-> len:size_t{v len > 0}
-> ctx_len:size_t
-> k:concrete_ops a_t len ctx_len
-> ctx:lbuffer (uint_t a_t SEC) ctx_len
-> a:lbuffer (uint_t a_t SEC) len
-> b:size_t ->
Stack unit
(requires fun h ->
live h a /\ live h ctx /\ disjoint a ctx /\
k.to.linv (as_seq h a) /\ k.to.linv_ctx (as_seq h ctx))
(ensures fun h0 _ h1 -> modifies (loc a) h0 h1 /\ k.to.linv (as_seq h1 a) /\
k.to.refl (as_seq h1 a) == S.exp_pow2 k.to.comm_monoid (k.to.refl (as_seq h0 a)) (v b))
// Fixed-window method using a precomputed table
//----------------------------------------------
inline_for_extraction noextract
let size_window_t (a_t:inttype_a) (len:size_t{v len > 0}) =
l:size_t{0 < v l /\ v l < bits a_t /\ v l < 32 /\ pow2 (v l) * v len <= max_size_t}
inline_for_extraction noextract
let table_len_t (len:size_t{v len > 0}) =
table_len:size_t{v table_len * v len <= max_size_t}
inline_for_extraction noextract | false | false | Hacl.Impl.Exponentiation.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val table_inv_t : a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
table_len: Hacl.Impl.Exponentiation.table_len_t len
-> Type | [] | Hacl.Impl.Exponentiation.table_inv_t | {
"file_name": "code/bignum/Hacl.Impl.Exponentiation.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
a_t: Hacl.Impl.Exponentiation.Definitions.inttype_a ->
len: Lib.IntTypes.size_t{Lib.IntTypes.v len > 0} ->
table_len: Hacl.Impl.Exponentiation.table_len_t len
-> Type | {
"end_col": 74,
"end_line": 129,
"start_col": 2,
"start_line": 128
} |