file_name
stringlengths 5
52
| name
stringlengths 4
95
| original_source_type
stringlengths 0
23k
| source_type
stringlengths 9
23k
| source_definition
stringlengths 9
57.9k
| source
dict | source_range
dict | file_context
stringlengths 0
721k
| dependencies
dict | opens_and_abbrevs
listlengths 2
94
| vconfig
dict | interleaved
bool 1
class | verbose_type
stringlengths 1
7.42k
| effect
stringclasses 118
values | effect_flags
sequencelengths 0
2
| mutual_with
sequencelengths 0
11
| ideal_premises
sequencelengths 0
236
| proof_features
sequencelengths 0
1
| is_simple_lemma
bool 2
classes | is_div
bool 2
classes | is_proof
bool 2
classes | is_simply_typed
bool 2
classes | is_type
bool 2
classes | partial_definition
stringlengths 5
3.99k
| completed_definiton
stringlengths 1
1.63M
| isa_cross_project_example
bool 1
class |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Hacl.EC.Ed25519.fst | Hacl.EC.Ed25519.felem_sub | val felem_sub: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fsub (F51.fevalh h0 a) (F51.fevalh h0 b)) | val felem_sub: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fsub (F51.fevalh h0 a) (F51.fevalh h0 b)) | let felem_sub a b out =
Hacl.Impl.Curve25519.Field51.fsub out a b;
Hacl.Bignum25519.reduce_513 out | {
"file_name": "code/ed25519/Hacl.EC.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 101,
"start_col": 0,
"start_line": 99
} | module Hacl.EC.Ed25519
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module F51 = Hacl.Impl.Ed25519.Field51
module SE = Spec.Ed25519
module SC = Spec.Curve25519
module ML = Hacl.Impl.Ed25519.Ladder
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
[@@ CPrologue
"/*******************************************************************************
Verified field arithmetic modulo p = 2^255 - 19.
This is a 64-bit optimized version, where a field element in radix-2^{51} is
represented as an array of five unsigned 64-bit integers, i.e., uint64_t[5].
*******************************************************************************/\n";
Comment "Write the additive identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_zero: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.zero)
let mk_felem_zero b =
Hacl.Bignum25519.make_zero b
[@@ Comment "Write the multiplicative identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_one: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.one)
let mk_felem_one b =
Hacl.Bignum25519.make_one b
[@@ Comment "Write `a + b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_add: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fadd (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_add a b out =
Hacl.Impl.Curve25519.Field51.fadd out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a - b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_sub: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fsub (F51.fevalh h0 a) (F51.fevalh h0 b)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.PointNegate.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDouble.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.PointConstants.fst.checked",
"Hacl.Impl.Ed25519.PointCompress.fst.checked",
"Hacl.Impl.Ed25519.PointAdd.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Impl.Curve25519.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.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.EC.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "ML"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"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.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Hacl.Impl.Ed25519.Field51.felem ->
b: Hacl.Impl.Ed25519.Field51.felem ->
out: Hacl.Impl.Ed25519.Field51.felem
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Ed25519.Field51.felem",
"Hacl.Bignum25519.reduce_513",
"Prims.unit",
"Hacl.Impl.Curve25519.Field51.fsub"
] | [] | false | true | false | false | false | let felem_sub a b out =
| Hacl.Impl.Curve25519.Field51.fsub out a b;
Hacl.Bignum25519.reduce_513 out | false |
Hacl.EC.Ed25519.fst | Hacl.EC.Ed25519.felem_sqr | val felem_sqr: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 a)) | val felem_sqr: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 a)) | let felem_sqr a out =
push_frame();
let tmp = create 5ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fsqr out a tmp;
pop_frame() | {
"file_name": "code/ed25519/Hacl.EC.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 148,
"start_col": 0,
"start_line": 144
} | module Hacl.EC.Ed25519
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module F51 = Hacl.Impl.Ed25519.Field51
module SE = Spec.Ed25519
module SC = Spec.Curve25519
module ML = Hacl.Impl.Ed25519.Ladder
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
[@@ CPrologue
"/*******************************************************************************
Verified field arithmetic modulo p = 2^255 - 19.
This is a 64-bit optimized version, where a field element in radix-2^{51} is
represented as an array of five unsigned 64-bit integers, i.e., uint64_t[5].
*******************************************************************************/\n";
Comment "Write the additive identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_zero: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.zero)
let mk_felem_zero b =
Hacl.Bignum25519.make_zero b
[@@ Comment "Write the multiplicative identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_one: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.one)
let mk_felem_one b =
Hacl.Bignum25519.make_one b
[@@ Comment "Write `a + b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_add: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fadd (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_add a b out =
Hacl.Impl.Curve25519.Field51.fadd out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a - b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_sub: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fsub (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_sub a b out =
Hacl.Impl.Curve25519.Field51.fsub out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a * b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_mul: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_mul a b out =
push_frame();
let tmp = create 10ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fmul out a b tmp;
pop_frame()
[@@ Comment "Write `a * a mod p` in `out`.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are either disjoint or equal"]
val felem_sqr: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 a)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.PointNegate.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDouble.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.PointConstants.fst.checked",
"Hacl.Impl.Ed25519.PointCompress.fst.checked",
"Hacl.Impl.Ed25519.PointAdd.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Impl.Curve25519.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.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.EC.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "ML"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"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.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Hacl.Impl.Ed25519.Field51.felem -> out: Hacl.Impl.Ed25519.Field51.felem
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Ed25519.Field51.felem",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.Curve25519.Field51.fsqr",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U128",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Hacl.Impl.Curve25519.Fields.Core.wide",
"Hacl.Impl.Curve25519.Fields.Core.M51",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.u128",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let felem_sqr a out =
| push_frame ();
let tmp = create 5ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fsqr out a tmp;
pop_frame () | false |
Hacl.EC.Ed25519.fst | Hacl.EC.Ed25519.felem_add | val felem_add: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fadd (F51.fevalh h0 a) (F51.fevalh h0 b)) | val felem_add: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fadd (F51.fevalh h0 a) (F51.fevalh h0 b)) | let felem_add a b out =
Hacl.Impl.Curve25519.Field51.fadd out a b;
Hacl.Bignum25519.reduce_513 out | {
"file_name": "code/ed25519/Hacl.EC.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 33,
"end_line": 76,
"start_col": 0,
"start_line": 74
} | module Hacl.EC.Ed25519
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module F51 = Hacl.Impl.Ed25519.Field51
module SE = Spec.Ed25519
module SC = Spec.Curve25519
module ML = Hacl.Impl.Ed25519.Ladder
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
[@@ CPrologue
"/*******************************************************************************
Verified field arithmetic modulo p = 2^255 - 19.
This is a 64-bit optimized version, where a field element in radix-2^{51} is
represented as an array of five unsigned 64-bit integers, i.e., uint64_t[5].
*******************************************************************************/\n";
Comment "Write the additive identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_zero: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.zero)
let mk_felem_zero b =
Hacl.Bignum25519.make_zero b
[@@ Comment "Write the multiplicative identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_one: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.one)
let mk_felem_one b =
Hacl.Bignum25519.make_one b
[@@ Comment "Write `a + b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_add: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fadd (F51.fevalh h0 a) (F51.fevalh h0 b)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.PointNegate.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDouble.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.PointConstants.fst.checked",
"Hacl.Impl.Ed25519.PointCompress.fst.checked",
"Hacl.Impl.Ed25519.PointAdd.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Impl.Curve25519.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.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.EC.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "ML"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"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.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Hacl.Impl.Ed25519.Field51.felem ->
b: Hacl.Impl.Ed25519.Field51.felem ->
out: Hacl.Impl.Ed25519.Field51.felem
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Ed25519.Field51.felem",
"Hacl.Bignum25519.reduce_513",
"Prims.unit",
"Hacl.Impl.Curve25519.Field51.fadd"
] | [] | false | true | false | false | false | let felem_add a b out =
| Hacl.Impl.Curve25519.Field51.fadd out a b;
Hacl.Bignum25519.reduce_513 out | false |
Hacl.EC.Ed25519.fst | Hacl.EC.Ed25519.point_compress | val point_compress: p:F51.point -> out:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ disjoint p out /\
F51.point_inv_t h p)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == SE.point_compress (F51.point_eval h0 p)) | val point_compress: p:F51.point -> out:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ disjoint p out /\
F51.point_inv_t h p)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == SE.point_compress (F51.point_eval h0 p)) | let point_compress p out =
Hacl.Impl.Ed25519.PointCompress.point_compress out p | {
"file_name": "code/ed25519/Hacl.EC.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 395,
"start_col": 0,
"start_line": 394
} | module Hacl.EC.Ed25519
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module F51 = Hacl.Impl.Ed25519.Field51
module SE = Spec.Ed25519
module SC = Spec.Curve25519
module ML = Hacl.Impl.Ed25519.Ladder
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
[@@ CPrologue
"/*******************************************************************************
Verified field arithmetic modulo p = 2^255 - 19.
This is a 64-bit optimized version, where a field element in radix-2^{51} is
represented as an array of five unsigned 64-bit integers, i.e., uint64_t[5].
*******************************************************************************/\n";
Comment "Write the additive identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_zero: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.zero)
let mk_felem_zero b =
Hacl.Bignum25519.make_zero b
[@@ Comment "Write the multiplicative identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_one: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.one)
let mk_felem_one b =
Hacl.Bignum25519.make_one b
[@@ Comment "Write `a + b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_add: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fadd (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_add a b out =
Hacl.Impl.Curve25519.Field51.fadd out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a - b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_sub: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fsub (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_sub a b out =
Hacl.Impl.Curve25519.Field51.fsub out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a * b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_mul: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_mul a b out =
push_frame();
let tmp = create 10ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fmul out a b tmp;
pop_frame()
[@@ Comment "Write `a * a mod p` in `out`.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are either disjoint or equal"]
val felem_sqr: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 a))
let felem_sqr a out =
push_frame();
let tmp = create 5ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fsqr out a tmp;
pop_frame()
[@@ Comment "Write `a ^ (p - 2) mod p` in `out`.
The function computes modular multiplicative inverse if `a` <> zero.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_inv: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\ disjoint a out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fpow (F51.fevalh h0 a) (SC.prime - 2))
let felem_inv a out =
Hacl.Bignum25519.inverse out a;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Load a little-endian field element from memory.
The argument `b` points to 32 bytes of valid memory, i.e., uint8_t[32].
The outparam `out` points to a field element of 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `b` and `out` are disjoint
NOTE that the function also performs the reduction modulo 2^255."]
val felem_load: b:lbuffer uint8 32ul -> out:F51.felem ->
Stack unit
(requires fun h -> live h b /\ live h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.as_nat h1 out == Lib.ByteSequence.nat_from_bytes_le (as_seq h0 b) % pow2 255)
let felem_load b out =
Hacl.Bignum25519.load_51 out b
[@@ Comment "Serialize a field element into little-endian memory.
The argument `a` points to a field element of 5 limbs in size, i.e., uint64_t[5].
The outparam `out` points to 32 bytes of valid memory, i.e., uint8_t[32].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_store: a:F51.felem -> out:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Lib.ByteSequence.nat_to_bytes_le 32 (F51.fevalh h0 a))
let felem_store a out =
Hacl.Bignum25519.store_51 out a
[@@ CPrologue
"/*******************************************************************************
Verified group operations for the edwards25519 elliptic curve of the form
−x^2 + y^2 = 1 − (121665/121666) * x^2 * y^2.
This is a 64-bit optimized version, where a group element in extended homogeneous
coordinates (X, Y, Z, T) is represented as an array of 20 unsigned 64-bit
integers, i.e., uint64_t[20].
*******************************************************************************/\n";
Comment "Write the point at infinity (additive identity) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_point_at_inf: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_point_at_infinity)
let mk_point_at_inf p =
Hacl.Impl.Ed25519.PointConstants.make_point_inf p
[@@ Comment "Write the base point (generator) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_base_point: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_g)
let mk_base_point p =
Spec.Ed25519.Lemmas.g_is_on_curve ();
Hacl.Impl.Ed25519.PointConstants.make_g p
[@@ Comment "Write `-p` in `out` (point negation).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are disjoint"]
val point_negate: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ disjoint out p /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == Spec.Ed25519.point_negate (F51.point_eval h0 p))
let point_negate p out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_negate (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointNegate.point_negate p out
[@@ Comment "Write `p + q` in `out` (point addition).
The arguments `p`, `q` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p`, `q`, and `out` are either pairwise disjoint or equal"]
val point_add: p:F51.point -> q:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ live h q /\
eq_or_disjoint p q /\
eq_or_disjoint p out /\ eq_or_disjoint q out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p) /\
F51.point_inv_t h q /\ F51.inv_ext_point (as_seq h q))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out ==
SE.point_add (F51.point_eval h0 p) (F51.point_eval h0 q))
let point_add p q out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_add_lemma
(F51.refl_ext_point (as_seq h0 p))
(F51.refl_ext_point (as_seq h0 q));
Hacl.Impl.Ed25519.PointAdd.point_add out p q
[@@ Comment "Write `p + p` in `out` (point doubling).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are either pairwise disjoint or equal"]
val point_double: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\
eq_or_disjoint p out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == SE.point_double (F51.point_eval h0 p))
let point_double p out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_double_lemma (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointDouble.point_double out p
[@@ Comment "Write `[scalar]p` in `out` (point multiplication or scalar multiplication).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
The argument `scalar` is meant to be 32 bytes in size, i.e., uint8_t[32].
The function first loads a little-endian scalar element from `scalar` and
then computes a point multiplication.
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `scalar`, `p`, and `out` are pairwise disjoint"]
val point_mul: scalar:lbuffer uint8 32ul -> p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h scalar /\ live h p /\ live h out /\
disjoint out p /\ disjoint out scalar /\
disjoint p scalar /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
SE.to_aff_point (F51.point_eval h1 out) ==
SE.to_aff_point (SE.point_mul (as_seq h0 scalar) (F51.point_eval h0 p)))
let point_mul scalar p out =
Hacl.Impl.Ed25519.Ladder.point_mul out scalar p
[@@ Comment "Checks whether `p` is equal to `q` (point equality).
The function returns `true` if `p` is equal to `q` and `false` otherwise.
The arguments `p` and `q` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `q` are either disjoint or equal"]
val point_eq: p:F51.point -> q:F51.point ->
Stack bool
(requires fun h ->
live h p /\ live h q /\ eq_or_disjoint p q /\
F51.point_inv_t h p /\ F51.point_inv_t h q)
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
(z <==> SE.point_equal (F51.point_eval h0 p) (F51.point_eval h0 q)))
let point_eq p q =
Hacl.Impl.Ed25519.PointEqual.point_equal p q
[@@ Comment "Compress a point in extended homogeneous coordinates to its compressed form.
The argument `p` points to a point of 20 limbs in size, i.e., uint64_t[20].
The outparam `out` points to 32 bytes of valid memory, i.e., uint8_t[32].
The function first converts a given point `p` from extended homogeneous to affine coordinates
and then writes [ 2^255 * (`x` % 2) + `y` ] in `out`.
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are disjoint"]
val point_compress: p:F51.point -> out:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ disjoint p out /\
F51.point_inv_t h p)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == SE.point_compress (F51.point_eval h0 p)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.PointNegate.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDouble.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.PointConstants.fst.checked",
"Hacl.Impl.Ed25519.PointCompress.fst.checked",
"Hacl.Impl.Ed25519.PointAdd.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Impl.Curve25519.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.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.EC.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "ML"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"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.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Hacl.Impl.Ed25519.Field51.point -> out: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Ed25519.Field51.point",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Ed25519.PointCompress.point_compress",
"Prims.unit"
] | [] | false | true | false | false | false | let point_compress p out =
| Hacl.Impl.Ed25519.PointCompress.point_compress out p | false |
Hacl.EC.Ed25519.fst | Hacl.EC.Ed25519.point_eq | val point_eq: p:F51.point -> q:F51.point ->
Stack bool
(requires fun h ->
live h p /\ live h q /\ eq_or_disjoint p q /\
F51.point_inv_t h p /\ F51.point_inv_t h q)
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
(z <==> SE.point_equal (F51.point_eval h0 p) (F51.point_eval h0 q))) | val point_eq: p:F51.point -> q:F51.point ->
Stack bool
(requires fun h ->
live h p /\ live h q /\ eq_or_disjoint p q /\
F51.point_inv_t h p /\ F51.point_inv_t h q)
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
(z <==> SE.point_equal (F51.point_eval h0 p) (F51.point_eval h0 q))) | let point_eq p q =
Hacl.Impl.Ed25519.PointEqual.point_equal p q | {
"file_name": "code/ed25519/Hacl.EC.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 372,
"start_col": 0,
"start_line": 371
} | module Hacl.EC.Ed25519
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module F51 = Hacl.Impl.Ed25519.Field51
module SE = Spec.Ed25519
module SC = Spec.Curve25519
module ML = Hacl.Impl.Ed25519.Ladder
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
[@@ CPrologue
"/*******************************************************************************
Verified field arithmetic modulo p = 2^255 - 19.
This is a 64-bit optimized version, where a field element in radix-2^{51} is
represented as an array of five unsigned 64-bit integers, i.e., uint64_t[5].
*******************************************************************************/\n";
Comment "Write the additive identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_zero: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.zero)
let mk_felem_zero b =
Hacl.Bignum25519.make_zero b
[@@ Comment "Write the multiplicative identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_one: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.one)
let mk_felem_one b =
Hacl.Bignum25519.make_one b
[@@ Comment "Write `a + b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_add: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fadd (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_add a b out =
Hacl.Impl.Curve25519.Field51.fadd out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a - b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_sub: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fsub (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_sub a b out =
Hacl.Impl.Curve25519.Field51.fsub out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a * b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_mul: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_mul a b out =
push_frame();
let tmp = create 10ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fmul out a b tmp;
pop_frame()
[@@ Comment "Write `a * a mod p` in `out`.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are either disjoint or equal"]
val felem_sqr: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 a))
let felem_sqr a out =
push_frame();
let tmp = create 5ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fsqr out a tmp;
pop_frame()
[@@ Comment "Write `a ^ (p - 2) mod p` in `out`.
The function computes modular multiplicative inverse if `a` <> zero.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_inv: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\ disjoint a out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fpow (F51.fevalh h0 a) (SC.prime - 2))
let felem_inv a out =
Hacl.Bignum25519.inverse out a;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Load a little-endian field element from memory.
The argument `b` points to 32 bytes of valid memory, i.e., uint8_t[32].
The outparam `out` points to a field element of 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `b` and `out` are disjoint
NOTE that the function also performs the reduction modulo 2^255."]
val felem_load: b:lbuffer uint8 32ul -> out:F51.felem ->
Stack unit
(requires fun h -> live h b /\ live h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.as_nat h1 out == Lib.ByteSequence.nat_from_bytes_le (as_seq h0 b) % pow2 255)
let felem_load b out =
Hacl.Bignum25519.load_51 out b
[@@ Comment "Serialize a field element into little-endian memory.
The argument `a` points to a field element of 5 limbs in size, i.e., uint64_t[5].
The outparam `out` points to 32 bytes of valid memory, i.e., uint8_t[32].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_store: a:F51.felem -> out:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Lib.ByteSequence.nat_to_bytes_le 32 (F51.fevalh h0 a))
let felem_store a out =
Hacl.Bignum25519.store_51 out a
[@@ CPrologue
"/*******************************************************************************
Verified group operations for the edwards25519 elliptic curve of the form
−x^2 + y^2 = 1 − (121665/121666) * x^2 * y^2.
This is a 64-bit optimized version, where a group element in extended homogeneous
coordinates (X, Y, Z, T) is represented as an array of 20 unsigned 64-bit
integers, i.e., uint64_t[20].
*******************************************************************************/\n";
Comment "Write the point at infinity (additive identity) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_point_at_inf: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_point_at_infinity)
let mk_point_at_inf p =
Hacl.Impl.Ed25519.PointConstants.make_point_inf p
[@@ Comment "Write the base point (generator) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_base_point: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_g)
let mk_base_point p =
Spec.Ed25519.Lemmas.g_is_on_curve ();
Hacl.Impl.Ed25519.PointConstants.make_g p
[@@ Comment "Write `-p` in `out` (point negation).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are disjoint"]
val point_negate: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ disjoint out p /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == Spec.Ed25519.point_negate (F51.point_eval h0 p))
let point_negate p out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_negate (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointNegate.point_negate p out
[@@ Comment "Write `p + q` in `out` (point addition).
The arguments `p`, `q` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p`, `q`, and `out` are either pairwise disjoint or equal"]
val point_add: p:F51.point -> q:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ live h q /\
eq_or_disjoint p q /\
eq_or_disjoint p out /\ eq_or_disjoint q out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p) /\
F51.point_inv_t h q /\ F51.inv_ext_point (as_seq h q))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out ==
SE.point_add (F51.point_eval h0 p) (F51.point_eval h0 q))
let point_add p q out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_add_lemma
(F51.refl_ext_point (as_seq h0 p))
(F51.refl_ext_point (as_seq h0 q));
Hacl.Impl.Ed25519.PointAdd.point_add out p q
[@@ Comment "Write `p + p` in `out` (point doubling).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are either pairwise disjoint or equal"]
val point_double: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\
eq_or_disjoint p out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == SE.point_double (F51.point_eval h0 p))
let point_double p out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_double_lemma (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointDouble.point_double out p
[@@ Comment "Write `[scalar]p` in `out` (point multiplication or scalar multiplication).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
The argument `scalar` is meant to be 32 bytes in size, i.e., uint8_t[32].
The function first loads a little-endian scalar element from `scalar` and
then computes a point multiplication.
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `scalar`, `p`, and `out` are pairwise disjoint"]
val point_mul: scalar:lbuffer uint8 32ul -> p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h scalar /\ live h p /\ live h out /\
disjoint out p /\ disjoint out scalar /\
disjoint p scalar /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
SE.to_aff_point (F51.point_eval h1 out) ==
SE.to_aff_point (SE.point_mul (as_seq h0 scalar) (F51.point_eval h0 p)))
let point_mul scalar p out =
Hacl.Impl.Ed25519.Ladder.point_mul out scalar p
[@@ Comment "Checks whether `p` is equal to `q` (point equality).
The function returns `true` if `p` is equal to `q` and `false` otherwise.
The arguments `p` and `q` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `q` are either disjoint or equal"]
val point_eq: p:F51.point -> q:F51.point ->
Stack bool
(requires fun h ->
live h p /\ live h q /\ eq_or_disjoint p q /\
F51.point_inv_t h p /\ F51.point_inv_t h q)
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
(z <==> SE.point_equal (F51.point_eval h0 p) (F51.point_eval h0 q))) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.PointNegate.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDouble.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.PointConstants.fst.checked",
"Hacl.Impl.Ed25519.PointCompress.fst.checked",
"Hacl.Impl.Ed25519.PointAdd.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Impl.Curve25519.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.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.EC.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "ML"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"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.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Hacl.Impl.Ed25519.Field51.point -> q: Hacl.Impl.Ed25519.Field51.point
-> FStar.HyperStack.ST.Stack Prims.bool | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Ed25519.Field51.point",
"Hacl.Impl.Ed25519.PointEqual.point_equal",
"Prims.bool"
] | [] | false | true | false | false | false | let point_eq p q =
| Hacl.Impl.Ed25519.PointEqual.point_equal p q | false |
Hacl.EC.Ed25519.fst | Hacl.EC.Ed25519.felem_mul | val felem_mul: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b)) | val felem_mul: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b)) | let felem_mul a b out =
push_frame();
let tmp = create 10ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fmul out a b tmp;
pop_frame() | {
"file_name": "code/ed25519/Hacl.EC.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 125,
"start_col": 0,
"start_line": 121
} | module Hacl.EC.Ed25519
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module F51 = Hacl.Impl.Ed25519.Field51
module SE = Spec.Ed25519
module SC = Spec.Curve25519
module ML = Hacl.Impl.Ed25519.Ladder
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
[@@ CPrologue
"/*******************************************************************************
Verified field arithmetic modulo p = 2^255 - 19.
This is a 64-bit optimized version, where a field element in radix-2^{51} is
represented as an array of five unsigned 64-bit integers, i.e., uint64_t[5].
*******************************************************************************/\n";
Comment "Write the additive identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_zero: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.zero)
let mk_felem_zero b =
Hacl.Bignum25519.make_zero b
[@@ Comment "Write the multiplicative identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_one: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.one)
let mk_felem_one b =
Hacl.Bignum25519.make_one b
[@@ Comment "Write `a + b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_add: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fadd (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_add a b out =
Hacl.Impl.Curve25519.Field51.fadd out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a - b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_sub: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fsub (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_sub a b out =
Hacl.Impl.Curve25519.Field51.fsub out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a * b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_mul: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.PointNegate.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDouble.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.PointConstants.fst.checked",
"Hacl.Impl.Ed25519.PointCompress.fst.checked",
"Hacl.Impl.Ed25519.PointAdd.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Impl.Curve25519.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.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.EC.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "ML"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"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.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Hacl.Impl.Ed25519.Field51.felem ->
b: Hacl.Impl.Ed25519.Field51.felem ->
out: Hacl.Impl.Ed25519.Field51.felem
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Ed25519.Field51.felem",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Impl.Curve25519.Field51.fmul",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U128",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Hacl.Impl.Curve25519.Fields.Core.wide",
"Hacl.Impl.Curve25519.Fields.Core.M51",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.u128",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let felem_mul a b out =
| push_frame ();
let tmp = create 10ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fmul out a b tmp;
pop_frame () | false |
Hacl.EC.Ed25519.fst | Hacl.EC.Ed25519.point_decompress | val point_decompress: s:lbuffer uint8 32ul -> out:F51.point ->
Stack bool
(requires fun h ->
live h out /\ live h s /\ disjoint s out)
(ensures fun h0 b h1 -> modifies (loc out) h0 h1 /\
(b ==> F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out)) /\
(b <==> Some? (SE.point_decompress (as_seq h0 s))) /\
(b ==> (F51.point_eval h1 out == Some?.v (SE.point_decompress (as_seq h0 s))))) | val point_decompress: s:lbuffer uint8 32ul -> out:F51.point ->
Stack bool
(requires fun h ->
live h out /\ live h s /\ disjoint s out)
(ensures fun h0 b h1 -> modifies (loc out) h0 h1 /\
(b ==> F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out)) /\
(b <==> Some? (SE.point_decompress (as_seq h0 s))) /\
(b ==> (F51.point_eval h1 out == Some?.v (SE.point_decompress (as_seq h0 s))))) | let point_decompress s out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.point_decompress_lemma (as_seq h0 s);
Hacl.Impl.Ed25519.PointDecompress.point_decompress out s | {
"file_name": "code/ed25519/Hacl.EC.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 421,
"start_col": 0,
"start_line": 418
} | module Hacl.EC.Ed25519
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module F51 = Hacl.Impl.Ed25519.Field51
module SE = Spec.Ed25519
module SC = Spec.Curve25519
module ML = Hacl.Impl.Ed25519.Ladder
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
[@@ CPrologue
"/*******************************************************************************
Verified field arithmetic modulo p = 2^255 - 19.
This is a 64-bit optimized version, where a field element in radix-2^{51} is
represented as an array of five unsigned 64-bit integers, i.e., uint64_t[5].
*******************************************************************************/\n";
Comment "Write the additive identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_zero: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.zero)
let mk_felem_zero b =
Hacl.Bignum25519.make_zero b
[@@ Comment "Write the multiplicative identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_one: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.one)
let mk_felem_one b =
Hacl.Bignum25519.make_one b
[@@ Comment "Write `a + b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_add: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fadd (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_add a b out =
Hacl.Impl.Curve25519.Field51.fadd out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a - b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_sub: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fsub (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_sub a b out =
Hacl.Impl.Curve25519.Field51.fsub out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a * b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_mul: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_mul a b out =
push_frame();
let tmp = create 10ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fmul out a b tmp;
pop_frame()
[@@ Comment "Write `a * a mod p` in `out`.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are either disjoint or equal"]
val felem_sqr: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 a))
let felem_sqr a out =
push_frame();
let tmp = create 5ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fsqr out a tmp;
pop_frame()
[@@ Comment "Write `a ^ (p - 2) mod p` in `out`.
The function computes modular multiplicative inverse if `a` <> zero.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_inv: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\ disjoint a out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fpow (F51.fevalh h0 a) (SC.prime - 2))
let felem_inv a out =
Hacl.Bignum25519.inverse out a;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Load a little-endian field element from memory.
The argument `b` points to 32 bytes of valid memory, i.e., uint8_t[32].
The outparam `out` points to a field element of 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `b` and `out` are disjoint
NOTE that the function also performs the reduction modulo 2^255."]
val felem_load: b:lbuffer uint8 32ul -> out:F51.felem ->
Stack unit
(requires fun h -> live h b /\ live h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.as_nat h1 out == Lib.ByteSequence.nat_from_bytes_le (as_seq h0 b) % pow2 255)
let felem_load b out =
Hacl.Bignum25519.load_51 out b
[@@ Comment "Serialize a field element into little-endian memory.
The argument `a` points to a field element of 5 limbs in size, i.e., uint64_t[5].
The outparam `out` points to 32 bytes of valid memory, i.e., uint8_t[32].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_store: a:F51.felem -> out:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Lib.ByteSequence.nat_to_bytes_le 32 (F51.fevalh h0 a))
let felem_store a out =
Hacl.Bignum25519.store_51 out a
[@@ CPrologue
"/*******************************************************************************
Verified group operations for the edwards25519 elliptic curve of the form
−x^2 + y^2 = 1 − (121665/121666) * x^2 * y^2.
This is a 64-bit optimized version, where a group element in extended homogeneous
coordinates (X, Y, Z, T) is represented as an array of 20 unsigned 64-bit
integers, i.e., uint64_t[20].
*******************************************************************************/\n";
Comment "Write the point at infinity (additive identity) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_point_at_inf: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_point_at_infinity)
let mk_point_at_inf p =
Hacl.Impl.Ed25519.PointConstants.make_point_inf p
[@@ Comment "Write the base point (generator) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_base_point: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_g)
let mk_base_point p =
Spec.Ed25519.Lemmas.g_is_on_curve ();
Hacl.Impl.Ed25519.PointConstants.make_g p
[@@ Comment "Write `-p` in `out` (point negation).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are disjoint"]
val point_negate: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ disjoint out p /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == Spec.Ed25519.point_negate (F51.point_eval h0 p))
let point_negate p out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_negate (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointNegate.point_negate p out
[@@ Comment "Write `p + q` in `out` (point addition).
The arguments `p`, `q` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p`, `q`, and `out` are either pairwise disjoint or equal"]
val point_add: p:F51.point -> q:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ live h q /\
eq_or_disjoint p q /\
eq_or_disjoint p out /\ eq_or_disjoint q out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p) /\
F51.point_inv_t h q /\ F51.inv_ext_point (as_seq h q))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out ==
SE.point_add (F51.point_eval h0 p) (F51.point_eval h0 q))
let point_add p q out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_add_lemma
(F51.refl_ext_point (as_seq h0 p))
(F51.refl_ext_point (as_seq h0 q));
Hacl.Impl.Ed25519.PointAdd.point_add out p q
[@@ Comment "Write `p + p` in `out` (point doubling).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are either pairwise disjoint or equal"]
val point_double: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\
eq_or_disjoint p out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == SE.point_double (F51.point_eval h0 p))
let point_double p out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_double_lemma (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointDouble.point_double out p
[@@ Comment "Write `[scalar]p` in `out` (point multiplication or scalar multiplication).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
The argument `scalar` is meant to be 32 bytes in size, i.e., uint8_t[32].
The function first loads a little-endian scalar element from `scalar` and
then computes a point multiplication.
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `scalar`, `p`, and `out` are pairwise disjoint"]
val point_mul: scalar:lbuffer uint8 32ul -> p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h scalar /\ live h p /\ live h out /\
disjoint out p /\ disjoint out scalar /\
disjoint p scalar /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
SE.to_aff_point (F51.point_eval h1 out) ==
SE.to_aff_point (SE.point_mul (as_seq h0 scalar) (F51.point_eval h0 p)))
let point_mul scalar p out =
Hacl.Impl.Ed25519.Ladder.point_mul out scalar p
[@@ Comment "Checks whether `p` is equal to `q` (point equality).
The function returns `true` if `p` is equal to `q` and `false` otherwise.
The arguments `p` and `q` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `q` are either disjoint or equal"]
val point_eq: p:F51.point -> q:F51.point ->
Stack bool
(requires fun h ->
live h p /\ live h q /\ eq_or_disjoint p q /\
F51.point_inv_t h p /\ F51.point_inv_t h q)
(ensures fun h0 z h1 -> modifies0 h0 h1 /\
(z <==> SE.point_equal (F51.point_eval h0 p) (F51.point_eval h0 q)))
let point_eq p q =
Hacl.Impl.Ed25519.PointEqual.point_equal p q
[@@ Comment "Compress a point in extended homogeneous coordinates to its compressed form.
The argument `p` points to a point of 20 limbs in size, i.e., uint64_t[20].
The outparam `out` points to 32 bytes of valid memory, i.e., uint8_t[32].
The function first converts a given point `p` from extended homogeneous to affine coordinates
and then writes [ 2^255 * (`x` % 2) + `y` ] in `out`.
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are disjoint"]
val point_compress: p:F51.point -> out:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ disjoint p out /\
F51.point_inv_t h p)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == SE.point_compress (F51.point_eval h0 p))
let point_compress p out =
Hacl.Impl.Ed25519.PointCompress.point_compress out p
[@@ Comment "Decompress a point in extended homogeneous coordinates from its compressed form.
The function returns `true` for successful decompression of a compressed point
and `false` otherwise.
The argument `s` points to 32 bytes of valid memory, i.e., uint8_t[32].
The outparam `out` points to a point of 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `s` and `out` are disjoint"]
val point_decompress: s:lbuffer uint8 32ul -> out:F51.point ->
Stack bool
(requires fun h ->
live h out /\ live h s /\ disjoint s out)
(ensures fun h0 b h1 -> modifies (loc out) h0 h1 /\
(b ==> F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out)) /\
(b <==> Some? (SE.point_decompress (as_seq h0 s))) /\
(b ==> (F51.point_eval h1 out == Some?.v (SE.point_decompress (as_seq h0 s))))) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.PointNegate.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDouble.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.PointConstants.fst.checked",
"Hacl.Impl.Ed25519.PointCompress.fst.checked",
"Hacl.Impl.Ed25519.PointAdd.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Impl.Curve25519.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.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.EC.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "ML"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"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.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul -> out: Hacl.Impl.Ed25519.Field51.point
-> FStar.HyperStack.ST.Stack Prims.bool | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Ed25519.Field51.point",
"Hacl.Impl.Ed25519.PointDecompress.point_decompress",
"Prims.bool",
"Prims.unit",
"Spec.Ed25519.Lemmas.point_decompress_lemma",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let point_decompress s out =
| let h0 = ST.get () in
Spec.Ed25519.Lemmas.point_decompress_lemma (as_seq h0 s);
Hacl.Impl.Ed25519.PointDecompress.point_decompress out s | false |
Hacl.EC.Ed25519.fst | Hacl.EC.Ed25519.point_mul | val point_mul: scalar:lbuffer uint8 32ul -> p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h scalar /\ live h p /\ live h out /\
disjoint out p /\ disjoint out scalar /\
disjoint p scalar /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
SE.to_aff_point (F51.point_eval h1 out) ==
SE.to_aff_point (SE.point_mul (as_seq h0 scalar) (F51.point_eval h0 p))) | val point_mul: scalar:lbuffer uint8 32ul -> p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h scalar /\ live h p /\ live h out /\
disjoint out p /\ disjoint out scalar /\
disjoint p scalar /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
SE.to_aff_point (F51.point_eval h1 out) ==
SE.to_aff_point (SE.point_mul (as_seq h0 scalar) (F51.point_eval h0 p))) | let point_mul scalar p out =
Hacl.Impl.Ed25519.Ladder.point_mul out scalar p | {
"file_name": "code/ed25519/Hacl.EC.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 49,
"end_line": 351,
"start_col": 0,
"start_line": 350
} | module Hacl.EC.Ed25519
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module F51 = Hacl.Impl.Ed25519.Field51
module SE = Spec.Ed25519
module SC = Spec.Curve25519
module ML = Hacl.Impl.Ed25519.Ladder
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
[@@ CPrologue
"/*******************************************************************************
Verified field arithmetic modulo p = 2^255 - 19.
This is a 64-bit optimized version, where a field element in radix-2^{51} is
represented as an array of five unsigned 64-bit integers, i.e., uint64_t[5].
*******************************************************************************/\n";
Comment "Write the additive identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_zero: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.zero)
let mk_felem_zero b =
Hacl.Bignum25519.make_zero b
[@@ Comment "Write the multiplicative identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_one: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.one)
let mk_felem_one b =
Hacl.Bignum25519.make_one b
[@@ Comment "Write `a + b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_add: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fadd (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_add a b out =
Hacl.Impl.Curve25519.Field51.fadd out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a - b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_sub: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fsub (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_sub a b out =
Hacl.Impl.Curve25519.Field51.fsub out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a * b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_mul: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_mul a b out =
push_frame();
let tmp = create 10ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fmul out a b tmp;
pop_frame()
[@@ Comment "Write `a * a mod p` in `out`.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are either disjoint or equal"]
val felem_sqr: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 a))
let felem_sqr a out =
push_frame();
let tmp = create 5ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fsqr out a tmp;
pop_frame()
[@@ Comment "Write `a ^ (p - 2) mod p` in `out`.
The function computes modular multiplicative inverse if `a` <> zero.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_inv: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\ disjoint a out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fpow (F51.fevalh h0 a) (SC.prime - 2))
let felem_inv a out =
Hacl.Bignum25519.inverse out a;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Load a little-endian field element from memory.
The argument `b` points to 32 bytes of valid memory, i.e., uint8_t[32].
The outparam `out` points to a field element of 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `b` and `out` are disjoint
NOTE that the function also performs the reduction modulo 2^255."]
val felem_load: b:lbuffer uint8 32ul -> out:F51.felem ->
Stack unit
(requires fun h -> live h b /\ live h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.as_nat h1 out == Lib.ByteSequence.nat_from_bytes_le (as_seq h0 b) % pow2 255)
let felem_load b out =
Hacl.Bignum25519.load_51 out b
[@@ Comment "Serialize a field element into little-endian memory.
The argument `a` points to a field element of 5 limbs in size, i.e., uint64_t[5].
The outparam `out` points to 32 bytes of valid memory, i.e., uint8_t[32].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_store: a:F51.felem -> out:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Lib.ByteSequence.nat_to_bytes_le 32 (F51.fevalh h0 a))
let felem_store a out =
Hacl.Bignum25519.store_51 out a
[@@ CPrologue
"/*******************************************************************************
Verified group operations for the edwards25519 elliptic curve of the form
−x^2 + y^2 = 1 − (121665/121666) * x^2 * y^2.
This is a 64-bit optimized version, where a group element in extended homogeneous
coordinates (X, Y, Z, T) is represented as an array of 20 unsigned 64-bit
integers, i.e., uint64_t[20].
*******************************************************************************/\n";
Comment "Write the point at infinity (additive identity) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_point_at_inf: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_point_at_infinity)
let mk_point_at_inf p =
Hacl.Impl.Ed25519.PointConstants.make_point_inf p
[@@ Comment "Write the base point (generator) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_base_point: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_g)
let mk_base_point p =
Spec.Ed25519.Lemmas.g_is_on_curve ();
Hacl.Impl.Ed25519.PointConstants.make_g p
[@@ Comment "Write `-p` in `out` (point negation).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are disjoint"]
val point_negate: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ disjoint out p /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == Spec.Ed25519.point_negate (F51.point_eval h0 p))
let point_negate p out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_negate (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointNegate.point_negate p out
[@@ Comment "Write `p + q` in `out` (point addition).
The arguments `p`, `q` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p`, `q`, and `out` are either pairwise disjoint or equal"]
val point_add: p:F51.point -> q:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ live h q /\
eq_or_disjoint p q /\
eq_or_disjoint p out /\ eq_or_disjoint q out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p) /\
F51.point_inv_t h q /\ F51.inv_ext_point (as_seq h q))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out ==
SE.point_add (F51.point_eval h0 p) (F51.point_eval h0 q))
let point_add p q out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_add_lemma
(F51.refl_ext_point (as_seq h0 p))
(F51.refl_ext_point (as_seq h0 q));
Hacl.Impl.Ed25519.PointAdd.point_add out p q
[@@ Comment "Write `p + p` in `out` (point doubling).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are either pairwise disjoint or equal"]
val point_double: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\
eq_or_disjoint p out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == SE.point_double (F51.point_eval h0 p))
let point_double p out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_double_lemma (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointDouble.point_double out p
[@@ Comment "Write `[scalar]p` in `out` (point multiplication or scalar multiplication).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
The argument `scalar` is meant to be 32 bytes in size, i.e., uint8_t[32].
The function first loads a little-endian scalar element from `scalar` and
then computes a point multiplication.
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `scalar`, `p`, and `out` are pairwise disjoint"]
val point_mul: scalar:lbuffer uint8 32ul -> p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h scalar /\ live h p /\ live h out /\
disjoint out p /\ disjoint out scalar /\
disjoint p scalar /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
SE.to_aff_point (F51.point_eval h1 out) ==
SE.to_aff_point (SE.point_mul (as_seq h0 scalar) (F51.point_eval h0 p))) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.PointNegate.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDouble.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.PointConstants.fst.checked",
"Hacl.Impl.Ed25519.PointCompress.fst.checked",
"Hacl.Impl.Ed25519.PointAdd.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Impl.Curve25519.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.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.EC.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "ML"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"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.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
scalar: Lib.Buffer.lbuffer Lib.IntTypes.uint8 32ul ->
p: Hacl.Impl.Ed25519.Field51.point ->
out: Hacl.Impl.Ed25519.Field51.point
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Hacl.Impl.Ed25519.Field51.point",
"Hacl.Impl.Ed25519.Ladder.point_mul",
"Prims.unit"
] | [] | false | true | false | false | false | let point_mul scalar p out =
| Hacl.Impl.Ed25519.Ladder.point_mul out scalar p | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_mul_threshold | val bn_mul_threshold : Lib.IntTypes.size_t | let bn_mul_threshold = size K.bn_mul_threshold | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 27,
"start_col": 0,
"start_line": 27
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"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"
} | false | Lib.IntTypes.size_t | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.size",
"Hacl.Spec.Bignum.Karatsuba.bn_mul_threshold"
] | [] | false | false | false | true | false | let bn_mul_threshold =
| size K.bn_mul_threshold | false |
|
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_mul_uint32 | val bn_karatsuba_mul_uint32 : unit -> bn_karatsuba_mul_st U32 | val bn_karatsuba_mul_uint32 : unit -> bn_karatsuba_mul_st U32 | let rec bn_karatsuba_mul_uint32 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint32 aLen a b tmp res | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 254,
"start_col": 0,
"start_line": 253
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
#push-options "--z3rlimit 150"
(* from Jonathan:
let karatsuba_t = dst:bignum -> a:bignum -> b:bignum -> Stack unit ensures dst = a * b
inline_for_extraction
let karatsuba_open (self: unit -> karastuba_t): fun dst a b ->
... self () dst' a' b' ...
let rec karatsuba () = karatsuba_open karastuba
*)
inline_for_extraction noextract
let bn_karatsuba_mul_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t}
-> a:lbignum t len
-> b:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b))
inline_for_extraction noextract
val bn_karatsuba_mul_open: #t:limb_t -> (self: unit -> bn_karatsuba_mul_st t) -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_open #t (self: unit -> bn_karatsuba_mul_st t) len a b tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_mul_]]
(K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_mul_u len a len b res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let b0 = sub b 0ul len2 in
let b1 = sub b len2 len2 in
// tmp = [ t0_len2; t1_len2; ..]
let t0 = sub tmp 0ul len2 in
let t1 = sub tmp len2 len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
let c1 = bn_sign_abs b0 b1 tmp' t1 in
// tmp = [ t0_len2; t1_len2; t23_len; ..]
(**) let h0 = ST.get () in
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 t1 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 b0 tmp1 r01;
self () len2 a1 b1 tmp1 r23;
let c = bn_karatsuba_last len c0 c1 tmp res in
LowStar.Ignore.ignore c;
() end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> Hacl.Bignum.Karatsuba.bn_karatsuba_mul_st Lib.IntTypes.U32 | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Plus_Bang",
"Hacl.Bignum.Karatsuba.bn_karatsuba_mul_open",
"Hacl.Bignum.Karatsuba.bn_karatsuba_mul_uint32"
] | [
"recursion"
] | false | false | false | true | false | let rec bn_karatsuba_mul_uint32 () aLen a b tmp res =
| bn_karatsuba_mul_open bn_karatsuba_mul_uint32 aLen a b tmp res | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_mul_uint64 | val bn_karatsuba_mul_uint64 : unit -> bn_karatsuba_mul_st U64 | val bn_karatsuba_mul_uint64 : unit -> bn_karatsuba_mul_st U64 | let rec bn_karatsuba_mul_uint64 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint64 aLen a b tmp res | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 64,
"end_line": 259,
"start_col": 0,
"start_line": 258
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
#push-options "--z3rlimit 150"
(* from Jonathan:
let karatsuba_t = dst:bignum -> a:bignum -> b:bignum -> Stack unit ensures dst = a * b
inline_for_extraction
let karatsuba_open (self: unit -> karastuba_t): fun dst a b ->
... self () dst' a' b' ...
let rec karatsuba () = karatsuba_open karastuba
*)
inline_for_extraction noextract
let bn_karatsuba_mul_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t}
-> a:lbignum t len
-> b:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b))
inline_for_extraction noextract
val bn_karatsuba_mul_open: #t:limb_t -> (self: unit -> bn_karatsuba_mul_st t) -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_open #t (self: unit -> bn_karatsuba_mul_st t) len a b tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_mul_]]
(K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_mul_u len a len b res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let b0 = sub b 0ul len2 in
let b1 = sub b len2 len2 in
// tmp = [ t0_len2; t1_len2; ..]
let t0 = sub tmp 0ul len2 in
let t1 = sub tmp len2 len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
let c1 = bn_sign_abs b0 b1 tmp' t1 in
// tmp = [ t0_len2; t1_len2; t23_len; ..]
(**) let h0 = ST.get () in
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 t1 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 b0 tmp1 r01;
self () len2 a1 b1 tmp1 r23;
let c = bn_karatsuba_last len c0 c1 tmp res in
LowStar.Ignore.ignore c;
() end
val bn_karatsuba_mul_uint32 : unit -> bn_karatsuba_mul_st U32
let rec bn_karatsuba_mul_uint32 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint32 aLen a b tmp res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> Hacl.Bignum.Karatsuba.bn_karatsuba_mul_st Lib.IntTypes.U64 | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.U64",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Plus_Bang",
"Hacl.Bignum.Karatsuba.bn_karatsuba_mul_open",
"Hacl.Bignum.Karatsuba.bn_karatsuba_mul_uint64"
] | [
"recursion"
] | false | false | false | true | false | let rec bn_karatsuba_mul_uint64 () aLen a b tmp res =
| bn_karatsuba_mul_open bn_karatsuba_mul_uint64 aLen a b tmp res | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_ | val bn_karatsuba_sqr_: #t:limb_t -> bn_karatsuba_sqr_st t | val bn_karatsuba_sqr_: #t:limb_t -> bn_karatsuba_sqr_st t | let bn_karatsuba_sqr_ #t =
match t with
| U32 -> bn_karatsuba_sqr_uint32 ()
| U64 -> bn_karatsuba_sqr_uint64 () | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 388,
"start_col": 0,
"start_line": 385
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
#push-options "--z3rlimit 150"
(* from Jonathan:
let karatsuba_t = dst:bignum -> a:bignum -> b:bignum -> Stack unit ensures dst = a * b
inline_for_extraction
let karatsuba_open (self: unit -> karastuba_t): fun dst a b ->
... self () dst' a' b' ...
let rec karatsuba () = karatsuba_open karastuba
*)
inline_for_extraction noextract
let bn_karatsuba_mul_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t}
-> a:lbignum t len
-> b:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b))
inline_for_extraction noextract
val bn_karatsuba_mul_open: #t:limb_t -> (self: unit -> bn_karatsuba_mul_st t) -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_open #t (self: unit -> bn_karatsuba_mul_st t) len a b tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_mul_]]
(K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_mul_u len a len b res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let b0 = sub b 0ul len2 in
let b1 = sub b len2 len2 in
// tmp = [ t0_len2; t1_len2; ..]
let t0 = sub tmp 0ul len2 in
let t1 = sub tmp len2 len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
let c1 = bn_sign_abs b0 b1 tmp' t1 in
// tmp = [ t0_len2; t1_len2; t23_len; ..]
(**) let h0 = ST.get () in
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 t1 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 b0 tmp1 r01;
self () len2 a1 b1 tmp1 r23;
let c = bn_karatsuba_last len c0 c1 tmp res in
LowStar.Ignore.ignore c;
() end
val bn_karatsuba_mul_uint32 : unit -> bn_karatsuba_mul_st U32
let rec bn_karatsuba_mul_uint32 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint32 aLen a b tmp res
val bn_karatsuba_mul_uint64 : unit -> bn_karatsuba_mul_st U64
let rec bn_karatsuba_mul_uint64 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint64 aLen a b tmp res
inline_for_extraction noextract
val bn_karatsuba_mul_: #t:limb_t -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_ #t =
match t with
| U32 -> bn_karatsuba_mul_uint32 ()
| U64 -> bn_karatsuba_mul_uint64 ()
//TODO: pass tmp as a parameter?
inline_for_extraction noextract
val bn_karatsuba_mul:
#t:limb_t
-> aLen:size_t{0 < v aLen /\ 4 * v aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul (as_seq h0 a) (as_seq h0 b))
let bn_karatsuba_mul #t aLen a b res =
push_frame ();
let tmp = create (4ul *! aLen) (uint #t 0) in
bn_karatsuba_mul_ aLen a b tmp res;
pop_frame ()
inline_for_extraction noextract
val bn_karatsuba_last_sqr:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba_sqr sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last_sqr #t aLen tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c3 = bn_sub_eq_len_u aLen t01 t23 t45 in
let c5 = c2 -. c3 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
inline_for_extraction noextract
let bn_karatsuba_sqr_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t /\ 0 < v len}
-> a:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint res a)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_sqr_ (v len) (as_seq h0 a))
inline_for_extraction noextract
val bn_karatsuba_sqr_open: #t:limb_t -> (self: unit -> bn_karatsuba_sqr_st t) -> bn_karatsuba_sqr_st t
let bn_karatsuba_sqr_open #t (self: unit -> bn_karatsuba_sqr_st t) len a tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_sqr_]]
(K.bn_karatsuba_sqr_ (v len) (as_seq h0 a));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_sqr_u len a res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let t0 = sub tmp 0ul len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
LowStar.Ignore.ignore c0;
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 tmp1 r01;
self () len2 a1 tmp1 r23;
let c = bn_karatsuba_last_sqr len tmp res in
LowStar.Ignore.ignore c;
() end
val bn_karatsuba_sqr_uint32 : unit -> bn_karatsuba_sqr_st U32
let rec bn_karatsuba_sqr_uint32 () aLen a tmp res =
bn_karatsuba_sqr_open bn_karatsuba_sqr_uint32 aLen a tmp res
val bn_karatsuba_sqr_uint64 : unit -> bn_karatsuba_sqr_st U64
let rec bn_karatsuba_sqr_uint64 () aLen a tmp res =
bn_karatsuba_sqr_open bn_karatsuba_sqr_uint64 aLen a tmp res
inline_for_extraction noextract | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_st t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_uint32",
"Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_uint64",
"Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_st"
] | [] | false | false | false | false | false | let bn_karatsuba_sqr_ #t =
| match t with
| U32 -> bn_karatsuba_sqr_uint32 ()
| U64 -> bn_karatsuba_sqr_uint64 () | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_lshift_add_in_place | val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i)) | val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i)) | let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r) | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 99,
"start_col": 0,
"start_line": 94
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"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"
} | false |
a: Hacl.Bignum.Definitions.lbignum t aLen ->
b1: Hacl.Bignum.Definitions.limb t ->
i: Lib.IntTypes.size_t{Lib.IntTypes.v i + 1 <= Lib.IntTypes.v aLen}
-> FStar.HyperStack.ST.Stack (Hacl.Spec.Bignum.Base.carry t) | FStar.HyperStack.ST.Stack | [] | [] | [
"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",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Hacl.Impl.Lib.update_sub_f_carry",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.op_Subtraction_Bang",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Spec.Bignum.Addition.bn_add1",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Pervasives.Native.tuple2",
"FStar.Seq.Properties.lseq",
"Prims.unit",
"Hacl.Bignum.Addition.bn_add1",
"FStar.HyperStack.ST.get",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.sub",
"Lib.Buffer.sub"
] | [] | false | true | false | false | false | let bn_lshift_add_in_place #t #aLen a b1 i =
| let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0
a
i
(aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r) | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_sign_abs | val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b)) | val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b)) | let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0 | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 51,
"start_col": 0,
"start_line": 46
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"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"
} | false |
a: Hacl.Bignum.Definitions.lbignum t aLen ->
b: Hacl.Bignum.Definitions.lbignum t aLen ->
tmp: Hacl.Bignum.Definitions.lbignum t aLen ->
res: Hacl.Bignum.Definitions.lbignum t aLen
-> FStar.HyperStack.ST.Stack (Hacl.Spec.Bignum.Base.carry t) | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.carry",
"Prims.unit",
"LowStar.Ignore.ignore",
"Lib.Buffer.map2T",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Base.mask_select",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.SEC",
"Lib.IntTypes.uint",
"Hacl.Bignum.Addition.bn_sub_eq_len_u"
] | [] | false | true | false | false | false | let bn_sign_abs #t #aLen a b tmp res =
| let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0 | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_uint32 | val bn_karatsuba_sqr_uint32 : unit -> bn_karatsuba_sqr_st U32 | val bn_karatsuba_sqr_uint32 : unit -> bn_karatsuba_sqr_st U32 | let rec bn_karatsuba_sqr_uint32 () aLen a tmp res =
bn_karatsuba_sqr_open bn_karatsuba_sqr_uint32 aLen a tmp res | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 375,
"start_col": 0,
"start_line": 374
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
#push-options "--z3rlimit 150"
(* from Jonathan:
let karatsuba_t = dst:bignum -> a:bignum -> b:bignum -> Stack unit ensures dst = a * b
inline_for_extraction
let karatsuba_open (self: unit -> karastuba_t): fun dst a b ->
... self () dst' a' b' ...
let rec karatsuba () = karatsuba_open karastuba
*)
inline_for_extraction noextract
let bn_karatsuba_mul_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t}
-> a:lbignum t len
-> b:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b))
inline_for_extraction noextract
val bn_karatsuba_mul_open: #t:limb_t -> (self: unit -> bn_karatsuba_mul_st t) -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_open #t (self: unit -> bn_karatsuba_mul_st t) len a b tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_mul_]]
(K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_mul_u len a len b res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let b0 = sub b 0ul len2 in
let b1 = sub b len2 len2 in
// tmp = [ t0_len2; t1_len2; ..]
let t0 = sub tmp 0ul len2 in
let t1 = sub tmp len2 len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
let c1 = bn_sign_abs b0 b1 tmp' t1 in
// tmp = [ t0_len2; t1_len2; t23_len; ..]
(**) let h0 = ST.get () in
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 t1 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 b0 tmp1 r01;
self () len2 a1 b1 tmp1 r23;
let c = bn_karatsuba_last len c0 c1 tmp res in
LowStar.Ignore.ignore c;
() end
val bn_karatsuba_mul_uint32 : unit -> bn_karatsuba_mul_st U32
let rec bn_karatsuba_mul_uint32 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint32 aLen a b tmp res
val bn_karatsuba_mul_uint64 : unit -> bn_karatsuba_mul_st U64
let rec bn_karatsuba_mul_uint64 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint64 aLen a b tmp res
inline_for_extraction noextract
val bn_karatsuba_mul_: #t:limb_t -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_ #t =
match t with
| U32 -> bn_karatsuba_mul_uint32 ()
| U64 -> bn_karatsuba_mul_uint64 ()
//TODO: pass tmp as a parameter?
inline_for_extraction noextract
val bn_karatsuba_mul:
#t:limb_t
-> aLen:size_t{0 < v aLen /\ 4 * v aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul (as_seq h0 a) (as_seq h0 b))
let bn_karatsuba_mul #t aLen a b res =
push_frame ();
let tmp = create (4ul *! aLen) (uint #t 0) in
bn_karatsuba_mul_ aLen a b tmp res;
pop_frame ()
inline_for_extraction noextract
val bn_karatsuba_last_sqr:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba_sqr sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last_sqr #t aLen tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c3 = bn_sub_eq_len_u aLen t01 t23 t45 in
let c5 = c2 -. c3 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
inline_for_extraction noextract
let bn_karatsuba_sqr_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t /\ 0 < v len}
-> a:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint res a)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_sqr_ (v len) (as_seq h0 a))
inline_for_extraction noextract
val bn_karatsuba_sqr_open: #t:limb_t -> (self: unit -> bn_karatsuba_sqr_st t) -> bn_karatsuba_sqr_st t
let bn_karatsuba_sqr_open #t (self: unit -> bn_karatsuba_sqr_st t) len a tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_sqr_]]
(K.bn_karatsuba_sqr_ (v len) (as_seq h0 a));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_sqr_u len a res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let t0 = sub tmp 0ul len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
LowStar.Ignore.ignore c0;
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 tmp1 r01;
self () len2 a1 tmp1 r23;
let c = bn_karatsuba_last_sqr len tmp res in
LowStar.Ignore.ignore c;
() end | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_st Lib.IntTypes.U32 | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.max_size_t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Plus_Bang",
"Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_open",
"Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_uint32"
] | [
"recursion"
] | false | false | false | true | false | let rec bn_karatsuba_sqr_uint32 () aLen a tmp res =
| bn_karatsuba_sqr_open bn_karatsuba_sqr_uint32 aLen a tmp res | false |
Pulse.Checker.Exists.fst | Pulse.Checker.Exists.check_intro_exists | val check_intro_exists
(g:env)
(pre:term)
(pre_typing:tot_typing g pre tm_vprop)
(post_hint:post_hint_opt g)
(res_ppname:ppname)
(st:st_term { intro_exists_witness_singleton st })
(vprop_typing: option (tot_typing g (intro_exists_vprop st) tm_vprop))
: T.Tac (checker_result_t g pre post_hint) | val check_intro_exists
(g:env)
(pre:term)
(pre_typing:tot_typing g pre tm_vprop)
(post_hint:post_hint_opt g)
(res_ppname:ppname)
(st:st_term { intro_exists_witness_singleton st })
(vprop_typing: option (tot_typing g (intro_exists_vprop st) tm_vprop))
: T.Tac (checker_result_t g pre post_hint) | let check_intro_exists
(g:env)
(pre:term)
(pre_typing:tot_typing g pre tm_vprop)
(post_hint:post_hint_opt g)
(res_ppname:ppname)
(st:st_term { intro_exists_witness_singleton st })
(vprop_typing: option (tot_typing g (intro_exists_vprop st) tm_vprop))
: T.Tac (checker_result_t g pre post_hint) =
let g = Pulse.Typing.Env.push_context g "check_intro_exists_non_erased" st.range in
let Tm_IntroExists { p=t; witnesses=[witness] } = st.term in
let (| t, t_typing |) =
match vprop_typing with
| Some typing -> (| t, typing |)
| _ -> check_vprop g t
in
if not (Tm_ExistsSL? (t <: term).t)
then fail g (Some st.range)
(Printf.sprintf "check_intro_exists_non_erased: vprop %s is not an existential"
(P.term_to_string t));
let Tm_ExistsSL u b p = (t <: term).t in
Pulse.Typing.FV.tot_typing_freevars t_typing;
let ty_typing, _ = Metatheory.tm_exists_inversion #g #u #b.binder_ty #p t_typing (fresh g) in
let (| witness, witness_typing |) =
check_term g witness T.E_Ghost b.binder_ty in
let d = T_IntroExists g u b p witness ty_typing t_typing witness_typing in
let (| c, d |) : (c:_ & st_typing g _ c) = (| _, d |) in
prove_post_hint (try_frame_pre pre_typing (match_comp_res_with_post_hint d post_hint) res_ppname) post_hint (t <: term).range | {
"file_name": "lib/steel/pulse/Pulse.Checker.Exists.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 127,
"end_line": 123,
"start_col": 0,
"start_line": 91
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Exists
open Pulse.Syntax
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Checker.Pure
open Pulse.Checker.Base
open Pulse.Checker.Prover
module T = FStar.Tactics.V2
module P = Pulse.Syntax.Printer
module FV = Pulse.Typing.FV
module Metatheory = Pulse.Typing.Metatheory
let vprop_as_list_typing (#g:env) (#p:term)
(t:tot_typing g p tm_vprop)
(x:term { List.Tot.memP x (vprop_as_list p) })
: tot_typing g x tm_vprop
= assume false; t
let terms_to_string (t:list term)
: T.Tac string
= String.concat "\n" (T.map Pulse.Syntax.Printer.term_to_string t)
let check_elim_exists
(g:env)
(pre:term)
(pre_typing:tot_typing g pre tm_vprop)
(post_hint:post_hint_opt g)
(res_ppname:ppname)
(t:st_term{Tm_ElimExists? t.term})
: T.Tac (checker_result_t g pre post_hint) =
let g = Pulse.Typing.Env.push_context g "check_elim_exists" t.range in
let Tm_ElimExists { p = t } = t.term in
let (| t, t_typing |) : (t:term & tot_typing g t tm_vprop ) =
match t.t with
| Tm_Unknown -> (
//There should be exactly one exists_ vprop in the context and we eliminate it
let ts = vprop_as_list pre in
let exist_tms = List.Tot.Base.filter #term (function | {t = Tm_ExistsSL _ _ _ } -> true | _ -> false) ts in
match exist_tms with
| [one] ->
assume (one `List.Tot.memP` ts);
(| one, vprop_as_list_typing pre_typing one |) //shouldn't need to check this again
| _ ->
fail g (Some t.range)
(Printf.sprintf "Could not decide which exists term to eliminate: choices are\n%s"
(terms_to_string exist_tms))
)
| _ ->
let t, _ = instantiate_term_implicits g t in
check_vprop g t
in
if not (Tm_ExistsSL? t.t)
then fail g (Some t.range)
(Printf.sprintf "check_elim_exists: elim_exists argument %s not an existential"
(P.term_to_string t));
let Tm_ExistsSL u { binder_ty=ty } p = t.t in
let (| u', ty_typing |) = check_universe g ty in
if eq_univ u u'
then let x = fresh g in
let d = T_ElimExists g u ty p x ty_typing t_typing in
prove_post_hint (try_frame_pre pre_typing (match_comp_res_with_post_hint d post_hint) res_ppname) post_hint t.range
else fail g (Some t.range)
(Printf.sprintf "check_elim_exists: universe checking failed, computed %s, expected %s"
(P.univ_to_string u') (P.univ_to_string u)) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.FV.fsti.checked",
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.String.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.Base.fst.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Exists.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.FV",
"short_module": "FV"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
g: Pulse.Typing.Env.env ->
pre: Pulse.Syntax.Base.term ->
pre_typing: Pulse.Typing.tot_typing g pre Pulse.Syntax.Base.tm_vprop ->
post_hint: Pulse.Typing.post_hint_opt g ->
res_ppname: Pulse.Syntax.Base.ppname ->
st: Pulse.Syntax.Base.st_term{Pulse.Checker.Exists.intro_exists_witness_singleton st} ->
vprop_typing:
FStar.Pervasives.Native.option (Pulse.Typing.tot_typing g
(Pulse.Checker.Exists.intro_exists_vprop st)
Pulse.Syntax.Base.tm_vprop)
-> FStar.Tactics.Effect.Tac (Pulse.Checker.Base.checker_result_t g pre post_hint) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.tm_vprop",
"Pulse.Typing.post_hint_opt",
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.st_term",
"Prims.b2t",
"Pulse.Checker.Exists.intro_exists_witness_singleton",
"FStar.Pervasives.Native.option",
"Pulse.Checker.Exists.intro_exists_vprop",
"Pulse.Syntax.Base.vprop",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"Pulse.Typing.universe_of",
"Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty",
"Pulse.Typing.Env.push_binding",
"Pulse.Typing.Env.fresh",
"Pulse.Syntax.Base.ppname_default",
"Pulse.Typing.typing",
"FStar.Stubs.TypeChecker.Core.E_Ghost",
"Pulse.Syntax.Base.comp",
"Pulse.Typing.st_typing",
"Pulse.Typing.wtag",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.ctag",
"Pulse.Syntax.Base.STT_Ghost",
"Pulse.Syntax.Base.Tm_IntroExists",
"Pulse.Syntax.Base.Mkst_term'__Tm_IntroExists__payload",
"Pulse.Syntax.Base.tm_exists_sl",
"Prims.Cons",
"Prims.Nil",
"Pulse.Checker.Prover.prove_post_hint",
"Pulse.Syntax.Base.__proj__Mkterm__item__range",
"Pulse.Checker.Base.checker_result_t",
"FStar.Pervasives.Native.None",
"Pulse.Typing.post_hint_t",
"Pulse.Checker.Prover.try_frame_pre",
"FStar.Pervasives.dtuple3",
"Pulse.Syntax.Base.comp_st",
"Pulse.Checker.Base.match_comp_res_with_post_hint",
"Prims.dtuple2",
"Prims.Mkdtuple2",
"Pulse.Typing.comp_intro_exists",
"Pulse.Typing.T_IntroExists",
"Pulse.Checker.Pure.check_term",
"FStar.Pervasives.Native.tuple2",
"Pulse.Typing.Metatheory.Base.tm_exists_inversion",
"Prims.unit",
"Pulse.Typing.FV.tot_typing_freevars",
"Pulse.Syntax.Base.term'",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Prims.op_Negation",
"Pulse.Syntax.Base.uu___is_Tm_ExistsSL",
"Pulse.Typing.Env.fail",
"Pulse.Syntax.Base.range",
"Pulse.Syntax.Base.__proj__Mkst_term__item__range",
"Prims.string",
"FStar.Printf.sprintf",
"Pulse.Syntax.Printer.term_to_string",
"Prims.bool",
"Pulse.Checker.Pure.check_vprop",
"Pulse.Syntax.Base.st_term'",
"Pulse.Syntax.Base.__proj__Mkst_term__item__term",
"Prims.eq2",
"Pulse.Typing.Env.push_context"
] | [] | false | true | false | false | false | let check_intro_exists
(g: env)
(pre: term)
(pre_typing: tot_typing g pre tm_vprop)
(post_hint: post_hint_opt g)
(res_ppname: ppname)
(st: st_term{intro_exists_witness_singleton st})
(vprop_typing: option (tot_typing g (intro_exists_vprop st) tm_vprop))
: T.Tac (checker_result_t g pre post_hint) =
| let g = Pulse.Typing.Env.push_context g "check_intro_exists_non_erased" st.range in
let Tm_IntroExists { p = t ; witnesses = [witness] } = st.term in
let (| t , t_typing |) =
match vprop_typing with
| Some typing -> (| t, typing |)
| _ -> check_vprop g t
in
if not (Tm_ExistsSL? (t <: term).t)
then
fail g
(Some st.range)
(Printf.sprintf "check_intro_exists_non_erased: vprop %s is not an existential"
(P.term_to_string t));
let Tm_ExistsSL u b p = (t <: term).t in
Pulse.Typing.FV.tot_typing_freevars t_typing;
let ty_typing, _ = Metatheory.tm_exists_inversion #g #u #b.binder_ty #p t_typing (fresh g) in
let (| witness , witness_typing |) = check_term g witness T.E_Ghost b.binder_ty in
let d = T_IntroExists g u b p witness ty_typing t_typing witness_typing in
let (| c , d |):(c: _ & st_typing g _ c) = (| _, d |) in
prove_post_hint (try_frame_pre pre_typing (match_comp_res_with_post_hint d post_hint) res_ppname)
post_hint
(t <: term).range | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_mul_ | val bn_karatsuba_mul_: #t:limb_t -> bn_karatsuba_mul_st t | val bn_karatsuba_mul_: #t:limb_t -> bn_karatsuba_mul_st t | let bn_karatsuba_mul_ #t =
match t with
| U32 -> bn_karatsuba_mul_uint32 ()
| U64 -> bn_karatsuba_mul_uint64 () | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 267,
"start_col": 0,
"start_line": 264
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
#push-options "--z3rlimit 150"
(* from Jonathan:
let karatsuba_t = dst:bignum -> a:bignum -> b:bignum -> Stack unit ensures dst = a * b
inline_for_extraction
let karatsuba_open (self: unit -> karastuba_t): fun dst a b ->
... self () dst' a' b' ...
let rec karatsuba () = karatsuba_open karastuba
*)
inline_for_extraction noextract
let bn_karatsuba_mul_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t}
-> a:lbignum t len
-> b:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b))
inline_for_extraction noextract
val bn_karatsuba_mul_open: #t:limb_t -> (self: unit -> bn_karatsuba_mul_st t) -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_open #t (self: unit -> bn_karatsuba_mul_st t) len a b tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_mul_]]
(K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_mul_u len a len b res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let b0 = sub b 0ul len2 in
let b1 = sub b len2 len2 in
// tmp = [ t0_len2; t1_len2; ..]
let t0 = sub tmp 0ul len2 in
let t1 = sub tmp len2 len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
let c1 = bn_sign_abs b0 b1 tmp' t1 in
// tmp = [ t0_len2; t1_len2; t23_len; ..]
(**) let h0 = ST.get () in
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 t1 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 b0 tmp1 r01;
self () len2 a1 b1 tmp1 r23;
let c = bn_karatsuba_last len c0 c1 tmp res in
LowStar.Ignore.ignore c;
() end
val bn_karatsuba_mul_uint32 : unit -> bn_karatsuba_mul_st U32
let rec bn_karatsuba_mul_uint32 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint32 aLen a b tmp res
val bn_karatsuba_mul_uint64 : unit -> bn_karatsuba_mul_st U64
let rec bn_karatsuba_mul_uint64 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint64 aLen a b tmp res
inline_for_extraction noextract | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Bignum.Karatsuba.bn_karatsuba_mul_st t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.Karatsuba.bn_karatsuba_mul_uint32",
"Hacl.Bignum.Karatsuba.bn_karatsuba_mul_uint64",
"Hacl.Bignum.Karatsuba.bn_karatsuba_mul_st"
] | [] | false | false | false | false | false | let bn_karatsuba_mul_ #t =
| match t with
| U32 -> bn_karatsuba_mul_uint32 ()
| U64 -> bn_karatsuba_mul_uint64 () | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_uint64 | val bn_karatsuba_sqr_uint64 : unit -> bn_karatsuba_sqr_st U64 | val bn_karatsuba_sqr_uint64 : unit -> bn_karatsuba_sqr_st U64 | let rec bn_karatsuba_sqr_uint64 () aLen a tmp res =
bn_karatsuba_sqr_open bn_karatsuba_sqr_uint64 aLen a tmp res | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 380,
"start_col": 0,
"start_line": 379
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
#push-options "--z3rlimit 150"
(* from Jonathan:
let karatsuba_t = dst:bignum -> a:bignum -> b:bignum -> Stack unit ensures dst = a * b
inline_for_extraction
let karatsuba_open (self: unit -> karastuba_t): fun dst a b ->
... self () dst' a' b' ...
let rec karatsuba () = karatsuba_open karastuba
*)
inline_for_extraction noextract
let bn_karatsuba_mul_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t}
-> a:lbignum t len
-> b:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b))
inline_for_extraction noextract
val bn_karatsuba_mul_open: #t:limb_t -> (self: unit -> bn_karatsuba_mul_st t) -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_open #t (self: unit -> bn_karatsuba_mul_st t) len a b tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_mul_]]
(K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_mul_u len a len b res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let b0 = sub b 0ul len2 in
let b1 = sub b len2 len2 in
// tmp = [ t0_len2; t1_len2; ..]
let t0 = sub tmp 0ul len2 in
let t1 = sub tmp len2 len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
let c1 = bn_sign_abs b0 b1 tmp' t1 in
// tmp = [ t0_len2; t1_len2; t23_len; ..]
(**) let h0 = ST.get () in
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 t1 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 b0 tmp1 r01;
self () len2 a1 b1 tmp1 r23;
let c = bn_karatsuba_last len c0 c1 tmp res in
LowStar.Ignore.ignore c;
() end
val bn_karatsuba_mul_uint32 : unit -> bn_karatsuba_mul_st U32
let rec bn_karatsuba_mul_uint32 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint32 aLen a b tmp res
val bn_karatsuba_mul_uint64 : unit -> bn_karatsuba_mul_st U64
let rec bn_karatsuba_mul_uint64 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint64 aLen a b tmp res
inline_for_extraction noextract
val bn_karatsuba_mul_: #t:limb_t -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_ #t =
match t with
| U32 -> bn_karatsuba_mul_uint32 ()
| U64 -> bn_karatsuba_mul_uint64 ()
//TODO: pass tmp as a parameter?
inline_for_extraction noextract
val bn_karatsuba_mul:
#t:limb_t
-> aLen:size_t{0 < v aLen /\ 4 * v aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul (as_seq h0 a) (as_seq h0 b))
let bn_karatsuba_mul #t aLen a b res =
push_frame ();
let tmp = create (4ul *! aLen) (uint #t 0) in
bn_karatsuba_mul_ aLen a b tmp res;
pop_frame ()
inline_for_extraction noextract
val bn_karatsuba_last_sqr:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba_sqr sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last_sqr #t aLen tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c3 = bn_sub_eq_len_u aLen t01 t23 t45 in
let c5 = c2 -. c3 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
inline_for_extraction noextract
let bn_karatsuba_sqr_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t /\ 0 < v len}
-> a:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint res a)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_sqr_ (v len) (as_seq h0 a))
inline_for_extraction noextract
val bn_karatsuba_sqr_open: #t:limb_t -> (self: unit -> bn_karatsuba_sqr_st t) -> bn_karatsuba_sqr_st t
let bn_karatsuba_sqr_open #t (self: unit -> bn_karatsuba_sqr_st t) len a tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_sqr_]]
(K.bn_karatsuba_sqr_ (v len) (as_seq h0 a));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_sqr_u len a res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let t0 = sub tmp 0ul len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
LowStar.Ignore.ignore c0;
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 tmp1 r01;
self () len2 a1 tmp1 r23;
let c = bn_karatsuba_last_sqr len tmp res in
LowStar.Ignore.ignore c;
() end
val bn_karatsuba_sqr_uint32 : unit -> bn_karatsuba_sqr_st U32
let rec bn_karatsuba_sqr_uint32 () aLen a tmp res =
bn_karatsuba_sqr_open bn_karatsuba_sqr_uint32 aLen a tmp res | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_st Lib.IntTypes.U64 | Prims.Tot | [
"total"
] | [] | [
"Prims.unit",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.max_size_t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.U64",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Plus_Bang",
"Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_open",
"Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_uint64"
] | [
"recursion"
] | false | false | false | true | false | let rec bn_karatsuba_sqr_uint64 () aLen a tmp res =
| bn_karatsuba_sqr_open bn_karatsuba_sqr_uint64 aLen a tmp res | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_mul_st | val bn_karatsuba_mul_st : t: Hacl.Bignum.Definitions.limb_t -> Type0 | let bn_karatsuba_mul_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t}
-> a:lbignum t len
-> b:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b)) | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 77,
"end_line": 209,
"start_col": 0,
"start_line": 197
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
#push-options "--z3rlimit 150"
(* from Jonathan:
let karatsuba_t = dst:bignum -> a:bignum -> b:bignum -> Stack unit ensures dst = a * b
inline_for_extraction
let karatsuba_open (self: unit -> karastuba_t): fun dst a b ->
... self () dst' a' b' ...
let rec karatsuba () = karatsuba_open karastuba
*) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Hacl.Bignum.Definitions.limb_t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Plus_Bang",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"Lib.Buffer.eq_or_disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.op_Addition",
"Prims.int",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_"
] | [] | false | false | false | true | true | let bn_karatsuba_mul_st (t: limb_t) =
|
len: size_t{4 * v len <= max_size_t} ->
a: lbignum t len ->
b: lbignum t len ->
tmp: lbignum t (4ul *! len) ->
res: lbignum t (len +! len)
-> Stack unit
(requires
fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\ disjoint res tmp /\ disjoint tmp a /\
disjoint tmp b /\ disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures
fun h0 _ h1 ->
modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b)) | false |
|
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_st | val bn_karatsuba_sqr_st : t: Hacl.Bignum.Definitions.limb_t -> Type0 | let bn_karatsuba_sqr_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t /\ 0 < v len}
-> a:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint res a)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_sqr_ (v len) (as_seq h0 a)) | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 63,
"end_line": 338,
"start_col": 0,
"start_line": 328
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
#push-options "--z3rlimit 150"
(* from Jonathan:
let karatsuba_t = dst:bignum -> a:bignum -> b:bignum -> Stack unit ensures dst = a * b
inline_for_extraction
let karatsuba_open (self: unit -> karastuba_t): fun dst a b ->
... self () dst' a' b' ...
let rec karatsuba () = karatsuba_open karastuba
*)
inline_for_extraction noextract
let bn_karatsuba_mul_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t}
-> a:lbignum t len
-> b:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b))
inline_for_extraction noextract
val bn_karatsuba_mul_open: #t:limb_t -> (self: unit -> bn_karatsuba_mul_st t) -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_open #t (self: unit -> bn_karatsuba_mul_st t) len a b tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_mul_]]
(K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_mul_u len a len b res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let b0 = sub b 0ul len2 in
let b1 = sub b len2 len2 in
// tmp = [ t0_len2; t1_len2; ..]
let t0 = sub tmp 0ul len2 in
let t1 = sub tmp len2 len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
let c1 = bn_sign_abs b0 b1 tmp' t1 in
// tmp = [ t0_len2; t1_len2; t23_len; ..]
(**) let h0 = ST.get () in
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 t1 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 b0 tmp1 r01;
self () len2 a1 b1 tmp1 r23;
let c = bn_karatsuba_last len c0 c1 tmp res in
LowStar.Ignore.ignore c;
() end
val bn_karatsuba_mul_uint32 : unit -> bn_karatsuba_mul_st U32
let rec bn_karatsuba_mul_uint32 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint32 aLen a b tmp res
val bn_karatsuba_mul_uint64 : unit -> bn_karatsuba_mul_st U64
let rec bn_karatsuba_mul_uint64 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint64 aLen a b tmp res
inline_for_extraction noextract
val bn_karatsuba_mul_: #t:limb_t -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_ #t =
match t with
| U32 -> bn_karatsuba_mul_uint32 ()
| U64 -> bn_karatsuba_mul_uint64 ()
//TODO: pass tmp as a parameter?
inline_for_extraction noextract
val bn_karatsuba_mul:
#t:limb_t
-> aLen:size_t{0 < v aLen /\ 4 * v aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul (as_seq h0 a) (as_seq h0 b))
let bn_karatsuba_mul #t aLen a b res =
push_frame ();
let tmp = create (4ul *! aLen) (uint #t 0) in
bn_karatsuba_mul_ aLen a b tmp res;
pop_frame ()
inline_for_extraction noextract
val bn_karatsuba_last_sqr:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba_sqr sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last_sqr #t aLen tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c3 = bn_sub_eq_len_u aLen t01 t23 t45 in
let c5 = c2 -. c3 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Hacl.Bignum.Definitions.limb_t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.max_size_t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Plus_Bang",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Prims.eq2",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.op_Addition",
"Prims.int",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_"
] | [] | false | false | false | true | true | let bn_karatsuba_sqr_st (t: limb_t) =
|
len: size_t{4 * v len <= max_size_t /\ 0 < v len} ->
a: lbignum t len ->
tmp: lbignum t (4ul *! len) ->
res: lbignum t (len +! len)
-> Stack unit
(requires
fun h ->
live h a /\ live h res /\ live h tmp /\ disjoint res tmp /\ disjoint tmp a /\
disjoint res a)
(ensures
fun h0 _ h1 ->
modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_sqr_ (v len) (as_seq h0 a)) | false |
|
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_lshift_add_early_stop_in_place | val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i)) | val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i)) | let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 122,
"start_col": 0,
"start_line": 115
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"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"
} | false |
a: Hacl.Bignum.Definitions.lbignum t aLen ->
b: Hacl.Bignum.Definitions.lbignum t bLen ->
i: Lib.IntTypes.size_t{Lib.IntTypes.v i + Lib.IntTypes.v bLen <= Lib.IntTypes.v aLen}
-> FStar.HyperStack.ST.Stack (Hacl.Spec.Bignum.Base.carry t) | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Impl.Lib.update_sub_f_carry",
"Hacl.Bignum.Definitions.limb",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Spec.Bignum.Addition.bn_add",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Pervasives.Native.tuple2",
"FStar.Seq.Properties.lseq",
"Prims.unit",
"Hacl.Bignum.Addition.bn_add_eq_len_u",
"FStar.HyperStack.ST.get",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.sub"
] | [] | false | true | false | false | false | let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
| let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0
a
i
bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r)
in
c | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_middle_karatsuba | val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23)) | val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23)) | let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3 | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 24,
"end_line": 79,
"start_col": 0,
"start_line": 73
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"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"
} | false |
c0: Hacl.Spec.Bignum.Base.carry t ->
c1: Hacl.Spec.Bignum.Base.carry t ->
c2: Hacl.Spec.Bignum.Base.carry t ->
t01: Hacl.Bignum.Definitions.lbignum t aLen ->
t23: Hacl.Bignum.Definitions.lbignum t aLen ->
tmp: Hacl.Bignum.Definitions.lbignum t aLen ->
res: Hacl.Bignum.Definitions.lbignum t aLen
-> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t) | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Spec.Bignum.Base.mask_select",
"Hacl.Bignum.Definitions.limb",
"Prims.unit",
"Lib.Buffer.map2T",
"Lib.Buffer.MUT",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.uint",
"Lib.IntTypes.op_Plus_Dot",
"Hacl.Bignum.Addition.bn_add_eq_len_u",
"Hacl.Bignum.Addition.bn_sub_eq_len_u",
"Lib.IntTypes.op_Hat_Dot"
] | [] | false | true | false | false | false | let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
| let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in
let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in
let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3 | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_res | val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45)) | val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45)) | let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8 | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 147,
"start_col": 0,
"start_line": 141
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"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"
} | false |
r01: Hacl.Bignum.Definitions.lbignum t aLen ->
r23: Hacl.Bignum.Definitions.lbignum t aLen ->
c5: Hacl.Bignum.Definitions.limb t ->
t45: Hacl.Bignum.Definitions.lbignum t aLen ->
res: Hacl.Bignum.Definitions.lbignum t (aLen +! aLen)
-> FStar.HyperStack.ST.Stack (Hacl.Spec.Bignum.Base.carry t) | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.max_size_t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.Definitions.limb",
"Lib.IntTypes.op_Plus_Bang",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Bignum.Karatsuba.bn_lshift_add_in_place",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Plus_Dot",
"Hacl.Bignum.Karatsuba.bn_lshift_add_early_stop_in_place",
"Lib.IntTypes.op_Slash_Dot",
"FStar.UInt32.__uint_to_t"
] | [] | false | true | false | false | false | let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
| let aLen2 = aLen /. 2ul in
[@@ inline_let ]let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8 | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_sqr | val bn_karatsuba_sqr:
#t:limb_t
-> aLen:size_t{0 < v aLen /\ 4 * v aLen <= max_size_t}
-> a:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack unit
(requires fun h -> live h a /\ live h res /\ disjoint res a)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_sqr (as_seq h0 a)) | val bn_karatsuba_sqr:
#t:limb_t
-> aLen:size_t{0 < v aLen /\ 4 * v aLen <= max_size_t}
-> a:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack unit
(requires fun h -> live h a /\ live h res /\ disjoint res a)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_sqr (as_seq h0 a)) | let bn_karatsuba_sqr #t aLen a res =
push_frame ();
let tmp = create (4ul *! aLen) (uint #t 0) in
bn_karatsuba_sqr_ aLen a tmp res;
pop_frame () | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 407,
"start_col": 0,
"start_line": 403
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
#push-options "--z3rlimit 150"
(* from Jonathan:
let karatsuba_t = dst:bignum -> a:bignum -> b:bignum -> Stack unit ensures dst = a * b
inline_for_extraction
let karatsuba_open (self: unit -> karastuba_t): fun dst a b ->
... self () dst' a' b' ...
let rec karatsuba () = karatsuba_open karastuba
*)
inline_for_extraction noextract
let bn_karatsuba_mul_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t}
-> a:lbignum t len
-> b:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b))
inline_for_extraction noextract
val bn_karatsuba_mul_open: #t:limb_t -> (self: unit -> bn_karatsuba_mul_st t) -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_open #t (self: unit -> bn_karatsuba_mul_st t) len a b tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_mul_]]
(K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_mul_u len a len b res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let b0 = sub b 0ul len2 in
let b1 = sub b len2 len2 in
// tmp = [ t0_len2; t1_len2; ..]
let t0 = sub tmp 0ul len2 in
let t1 = sub tmp len2 len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
let c1 = bn_sign_abs b0 b1 tmp' t1 in
// tmp = [ t0_len2; t1_len2; t23_len; ..]
(**) let h0 = ST.get () in
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 t1 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 b0 tmp1 r01;
self () len2 a1 b1 tmp1 r23;
let c = bn_karatsuba_last len c0 c1 tmp res in
LowStar.Ignore.ignore c;
() end
val bn_karatsuba_mul_uint32 : unit -> bn_karatsuba_mul_st U32
let rec bn_karatsuba_mul_uint32 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint32 aLen a b tmp res
val bn_karatsuba_mul_uint64 : unit -> bn_karatsuba_mul_st U64
let rec bn_karatsuba_mul_uint64 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint64 aLen a b tmp res
inline_for_extraction noextract
val bn_karatsuba_mul_: #t:limb_t -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_ #t =
match t with
| U32 -> bn_karatsuba_mul_uint32 ()
| U64 -> bn_karatsuba_mul_uint64 ()
//TODO: pass tmp as a parameter?
inline_for_extraction noextract
val bn_karatsuba_mul:
#t:limb_t
-> aLen:size_t{0 < v aLen /\ 4 * v aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul (as_seq h0 a) (as_seq h0 b))
let bn_karatsuba_mul #t aLen a b res =
push_frame ();
let tmp = create (4ul *! aLen) (uint #t 0) in
bn_karatsuba_mul_ aLen a b tmp res;
pop_frame ()
inline_for_extraction noextract
val bn_karatsuba_last_sqr:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba_sqr sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last_sqr #t aLen tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c3 = bn_sub_eq_len_u aLen t01 t23 t45 in
let c5 = c2 -. c3 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
inline_for_extraction noextract
let bn_karatsuba_sqr_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t /\ 0 < v len}
-> a:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint res a)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_sqr_ (v len) (as_seq h0 a))
inline_for_extraction noextract
val bn_karatsuba_sqr_open: #t:limb_t -> (self: unit -> bn_karatsuba_sqr_st t) -> bn_karatsuba_sqr_st t
let bn_karatsuba_sqr_open #t (self: unit -> bn_karatsuba_sqr_st t) len a tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_sqr_]]
(K.bn_karatsuba_sqr_ (v len) (as_seq h0 a));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_sqr_u len a res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let t0 = sub tmp 0ul len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
LowStar.Ignore.ignore c0;
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 tmp1 r01;
self () len2 a1 tmp1 r23;
let c = bn_karatsuba_last_sqr len tmp res in
LowStar.Ignore.ignore c;
() end
val bn_karatsuba_sqr_uint32 : unit -> bn_karatsuba_sqr_st U32
let rec bn_karatsuba_sqr_uint32 () aLen a tmp res =
bn_karatsuba_sqr_open bn_karatsuba_sqr_uint32 aLen a tmp res
val bn_karatsuba_sqr_uint64 : unit -> bn_karatsuba_sqr_st U64
let rec bn_karatsuba_sqr_uint64 () aLen a tmp res =
bn_karatsuba_sqr_open bn_karatsuba_sqr_uint64 aLen a tmp res
inline_for_extraction noextract
val bn_karatsuba_sqr_: #t:limb_t -> bn_karatsuba_sqr_st t
let bn_karatsuba_sqr_ #t =
match t with
| U32 -> bn_karatsuba_sqr_uint32 ()
| U64 -> bn_karatsuba_sqr_uint64 ()
//TODO: pass tmp as a parameter?
inline_for_extraction noextract
val bn_karatsuba_sqr:
#t:limb_t
-> aLen:size_t{0 < v aLen /\ 4 * v aLen <= max_size_t}
-> a:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack unit
(requires fun h -> live h a /\ live h res /\ disjoint res a)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_sqr (as_seq h0 a)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
aLen:
Lib.IntTypes.size_t
{0 < Lib.IntTypes.v aLen /\ 4 * Lib.IntTypes.v aLen <= Lib.IntTypes.max_size_t} ->
a: Hacl.Bignum.Definitions.lbignum t aLen ->
res: Hacl.Bignum.Definitions.lbignum t (aLen +! aLen)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Plus_Bang",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.IntTypes.mul",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let bn_karatsuba_sqr #t aLen a res =
| push_frame ();
let tmp = create (4ul *! aLen) (uint #t 0) in
bn_karatsuba_sqr_ aLen a tmp res;
pop_frame () | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_mul | val bn_karatsuba_mul:
#t:limb_t
-> aLen:size_t{0 < v aLen /\ 4 * v aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul (as_seq h0 a) (as_seq h0 b)) | val bn_karatsuba_mul:
#t:limb_t
-> aLen:size_t{0 < v aLen /\ 4 * v aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul (as_seq h0 a) (as_seq h0 b)) | let bn_karatsuba_mul #t aLen a b res =
push_frame ();
let tmp = create (4ul *! aLen) (uint #t 0) in
bn_karatsuba_mul_ aLen a b tmp res;
pop_frame () | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 14,
"end_line": 289,
"start_col": 0,
"start_line": 285
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
#push-options "--z3rlimit 150"
(* from Jonathan:
let karatsuba_t = dst:bignum -> a:bignum -> b:bignum -> Stack unit ensures dst = a * b
inline_for_extraction
let karatsuba_open (self: unit -> karastuba_t): fun dst a b ->
... self () dst' a' b' ...
let rec karatsuba () = karatsuba_open karastuba
*)
inline_for_extraction noextract
let bn_karatsuba_mul_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t}
-> a:lbignum t len
-> b:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b))
inline_for_extraction noextract
val bn_karatsuba_mul_open: #t:limb_t -> (self: unit -> bn_karatsuba_mul_st t) -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_open #t (self: unit -> bn_karatsuba_mul_st t) len a b tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_mul_]]
(K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_mul_u len a len b res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let b0 = sub b 0ul len2 in
let b1 = sub b len2 len2 in
// tmp = [ t0_len2; t1_len2; ..]
let t0 = sub tmp 0ul len2 in
let t1 = sub tmp len2 len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
let c1 = bn_sign_abs b0 b1 tmp' t1 in
// tmp = [ t0_len2; t1_len2; t23_len; ..]
(**) let h0 = ST.get () in
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 t1 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 b0 tmp1 r01;
self () len2 a1 b1 tmp1 r23;
let c = bn_karatsuba_last len c0 c1 tmp res in
LowStar.Ignore.ignore c;
() end
val bn_karatsuba_mul_uint32 : unit -> bn_karatsuba_mul_st U32
let rec bn_karatsuba_mul_uint32 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint32 aLen a b tmp res
val bn_karatsuba_mul_uint64 : unit -> bn_karatsuba_mul_st U64
let rec bn_karatsuba_mul_uint64 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint64 aLen a b tmp res
inline_for_extraction noextract
val bn_karatsuba_mul_: #t:limb_t -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_ #t =
match t with
| U32 -> bn_karatsuba_mul_uint32 ()
| U64 -> bn_karatsuba_mul_uint64 ()
//TODO: pass tmp as a parameter?
inline_for_extraction noextract
val bn_karatsuba_mul:
#t:limb_t
-> aLen:size_t{0 < v aLen /\ 4 * v aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul (as_seq h0 a) (as_seq h0 b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
aLen:
Lib.IntTypes.size_t
{0 < Lib.IntTypes.v aLen /\ 4 * Lib.IntTypes.v aLen <= Lib.IntTypes.max_size_t} ->
a: Hacl.Bignum.Definitions.lbignum t aLen ->
b: Hacl.Bignum.Definitions.lbignum t aLen ->
res: Hacl.Bignum.Definitions.lbignum t (aLen +! aLen)
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Plus_Bang",
"FStar.HyperStack.ST.pop_frame",
"Prims.unit",
"Hacl.Bignum.Karatsuba.bn_karatsuba_mul_",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.IntTypes.mul",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.create",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.uint",
"Lib.IntTypes.SEC",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | false | true | false | false | false | let bn_karatsuba_mul #t aLen a b res =
| push_frame ();
let tmp = create (4ul *! aLen) (uint #t 0) in
bn_karatsuba_mul_ aLen a b tmp res;
pop_frame () | false |
Hacl.EC.Ed25519.fst | Hacl.EC.Ed25519.point_double | val point_double: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\
eq_or_disjoint p out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == SE.point_double (F51.point_eval h0 p)) | val point_double: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\
eq_or_disjoint p out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == SE.point_double (F51.point_eval h0 p)) | let point_double p out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_double_lemma (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointDouble.point_double out p | {
"file_name": "code/ed25519/Hacl.EC.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 324,
"start_col": 0,
"start_line": 321
} | module Hacl.EC.Ed25519
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module F51 = Hacl.Impl.Ed25519.Field51
module SE = Spec.Ed25519
module SC = Spec.Curve25519
module ML = Hacl.Impl.Ed25519.Ladder
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
[@@ CPrologue
"/*******************************************************************************
Verified field arithmetic modulo p = 2^255 - 19.
This is a 64-bit optimized version, where a field element in radix-2^{51} is
represented as an array of five unsigned 64-bit integers, i.e., uint64_t[5].
*******************************************************************************/\n";
Comment "Write the additive identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_zero: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.zero)
let mk_felem_zero b =
Hacl.Bignum25519.make_zero b
[@@ Comment "Write the multiplicative identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_one: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.one)
let mk_felem_one b =
Hacl.Bignum25519.make_one b
[@@ Comment "Write `a + b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_add: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fadd (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_add a b out =
Hacl.Impl.Curve25519.Field51.fadd out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a - b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_sub: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fsub (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_sub a b out =
Hacl.Impl.Curve25519.Field51.fsub out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a * b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_mul: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_mul a b out =
push_frame();
let tmp = create 10ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fmul out a b tmp;
pop_frame()
[@@ Comment "Write `a * a mod p` in `out`.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are either disjoint or equal"]
val felem_sqr: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 a))
let felem_sqr a out =
push_frame();
let tmp = create 5ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fsqr out a tmp;
pop_frame()
[@@ Comment "Write `a ^ (p - 2) mod p` in `out`.
The function computes modular multiplicative inverse if `a` <> zero.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_inv: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\ disjoint a out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fpow (F51.fevalh h0 a) (SC.prime - 2))
let felem_inv a out =
Hacl.Bignum25519.inverse out a;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Load a little-endian field element from memory.
The argument `b` points to 32 bytes of valid memory, i.e., uint8_t[32].
The outparam `out` points to a field element of 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `b` and `out` are disjoint
NOTE that the function also performs the reduction modulo 2^255."]
val felem_load: b:lbuffer uint8 32ul -> out:F51.felem ->
Stack unit
(requires fun h -> live h b /\ live h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.as_nat h1 out == Lib.ByteSequence.nat_from_bytes_le (as_seq h0 b) % pow2 255)
let felem_load b out =
Hacl.Bignum25519.load_51 out b
[@@ Comment "Serialize a field element into little-endian memory.
The argument `a` points to a field element of 5 limbs in size, i.e., uint64_t[5].
The outparam `out` points to 32 bytes of valid memory, i.e., uint8_t[32].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_store: a:F51.felem -> out:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Lib.ByteSequence.nat_to_bytes_le 32 (F51.fevalh h0 a))
let felem_store a out =
Hacl.Bignum25519.store_51 out a
[@@ CPrologue
"/*******************************************************************************
Verified group operations for the edwards25519 elliptic curve of the form
−x^2 + y^2 = 1 − (121665/121666) * x^2 * y^2.
This is a 64-bit optimized version, where a group element in extended homogeneous
coordinates (X, Y, Z, T) is represented as an array of 20 unsigned 64-bit
integers, i.e., uint64_t[20].
*******************************************************************************/\n";
Comment "Write the point at infinity (additive identity) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_point_at_inf: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_point_at_infinity)
let mk_point_at_inf p =
Hacl.Impl.Ed25519.PointConstants.make_point_inf p
[@@ Comment "Write the base point (generator) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_base_point: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_g)
let mk_base_point p =
Spec.Ed25519.Lemmas.g_is_on_curve ();
Hacl.Impl.Ed25519.PointConstants.make_g p
[@@ Comment "Write `-p` in `out` (point negation).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are disjoint"]
val point_negate: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ disjoint out p /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == Spec.Ed25519.point_negate (F51.point_eval h0 p))
let point_negate p out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_negate (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointNegate.point_negate p out
[@@ Comment "Write `p + q` in `out` (point addition).
The arguments `p`, `q` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p`, `q`, and `out` are either pairwise disjoint or equal"]
val point_add: p:F51.point -> q:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ live h q /\
eq_or_disjoint p q /\
eq_or_disjoint p out /\ eq_or_disjoint q out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p) /\
F51.point_inv_t h q /\ F51.inv_ext_point (as_seq h q))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out ==
SE.point_add (F51.point_eval h0 p) (F51.point_eval h0 q))
let point_add p q out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_add_lemma
(F51.refl_ext_point (as_seq h0 p))
(F51.refl_ext_point (as_seq h0 q));
Hacl.Impl.Ed25519.PointAdd.point_add out p q
[@@ Comment "Write `p + p` in `out` (point doubling).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are either pairwise disjoint or equal"]
val point_double: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\
eq_or_disjoint p out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == SE.point_double (F51.point_eval h0 p)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.PointNegate.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDouble.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.PointConstants.fst.checked",
"Hacl.Impl.Ed25519.PointCompress.fst.checked",
"Hacl.Impl.Ed25519.PointAdd.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Impl.Curve25519.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.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.EC.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "ML"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"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.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Hacl.Impl.Ed25519.Field51.point -> out: Hacl.Impl.Ed25519.Field51.point
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Ed25519.Field51.point",
"Hacl.Impl.Ed25519.PointDouble.point_double",
"Prims.unit",
"Spec.Ed25519.Lemmas.to_aff_point_double_lemma",
"Hacl.Impl.Ed25519.Field51.refl_ext_point",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint64",
"FStar.UInt32.__uint_to_t",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let point_double p out =
| let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_double_lemma (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointDouble.point_double out p | false |
Test.Lowstarize.fst | Test.Lowstarize.mk_int | val mk_int (i: int) : term | val mk_int (i: int) : term | let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i)) | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 19,
"start_col": 0,
"start_line": 18
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | i: Prims.int -> FStar.Stubs.Reflection.Types.term | Prims.Tot | [
"total"
] | [] | [
"Prims.int",
"FStar.Stubs.Reflection.V1.Builtins.pack_ln",
"FStar.Stubs.Reflection.V1.Data.Tv_Const",
"FStar.Stubs.Reflection.V1.Data.C_Int",
"FStar.Stubs.Reflection.Types.term"
] | [] | false | false | false | true | false | let mk_int (i: int) : term =
| pack_ln (Tv_Const (C_Int i)) | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_last_sqr | val bn_karatsuba_last_sqr:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba_sqr sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres))) | val bn_karatsuba_last_sqr:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba_sqr sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres))) | let bn_karatsuba_last_sqr #t aLen tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c3 = bn_sub_eq_len_u aLen t01 t23 t45 in
let c5 = c2 -. c3 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 324,
"start_col": 0,
"start_line": 309
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
#push-options "--z3rlimit 150"
(* from Jonathan:
let karatsuba_t = dst:bignum -> a:bignum -> b:bignum -> Stack unit ensures dst = a * b
inline_for_extraction
let karatsuba_open (self: unit -> karastuba_t): fun dst a b ->
... self () dst' a' b' ...
let rec karatsuba () = karatsuba_open karastuba
*)
inline_for_extraction noextract
let bn_karatsuba_mul_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t}
-> a:lbignum t len
-> b:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b))
inline_for_extraction noextract
val bn_karatsuba_mul_open: #t:limb_t -> (self: unit -> bn_karatsuba_mul_st t) -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_open #t (self: unit -> bn_karatsuba_mul_st t) len a b tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_mul_]]
(K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_mul_u len a len b res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let b0 = sub b 0ul len2 in
let b1 = sub b len2 len2 in
// tmp = [ t0_len2; t1_len2; ..]
let t0 = sub tmp 0ul len2 in
let t1 = sub tmp len2 len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
let c1 = bn_sign_abs b0 b1 tmp' t1 in
// tmp = [ t0_len2; t1_len2; t23_len; ..]
(**) let h0 = ST.get () in
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 t1 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 b0 tmp1 r01;
self () len2 a1 b1 tmp1 r23;
let c = bn_karatsuba_last len c0 c1 tmp res in
LowStar.Ignore.ignore c;
() end
val bn_karatsuba_mul_uint32 : unit -> bn_karatsuba_mul_st U32
let rec bn_karatsuba_mul_uint32 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint32 aLen a b tmp res
val bn_karatsuba_mul_uint64 : unit -> bn_karatsuba_mul_st U64
let rec bn_karatsuba_mul_uint64 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint64 aLen a b tmp res
inline_for_extraction noextract
val bn_karatsuba_mul_: #t:limb_t -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_ #t =
match t with
| U32 -> bn_karatsuba_mul_uint32 ()
| U64 -> bn_karatsuba_mul_uint64 ()
//TODO: pass tmp as a parameter?
inline_for_extraction noextract
val bn_karatsuba_mul:
#t:limb_t
-> aLen:size_t{0 < v aLen /\ 4 * v aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul (as_seq h0 a) (as_seq h0 b))
let bn_karatsuba_mul #t aLen a b res =
push_frame ();
let tmp = create (4ul *! aLen) (uint #t 0) in
bn_karatsuba_mul_ aLen a b tmp res;
pop_frame ()
inline_for_extraction noextract
val bn_karatsuba_last_sqr:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba_sqr sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
aLen:
Lib.IntTypes.size_t
{ 4 * Lib.IntTypes.v aLen <= Lib.IntTypes.max_size_t /\ Lib.IntTypes.v aLen % 2 = 0 /\
0 < Lib.IntTypes.v aLen } ->
tmp: Hacl.Bignum.Definitions.lbignum t (4ul *! aLen) ->
res: Hacl.Bignum.Definitions.lbignum t (aLen +! aLen)
-> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t) | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.max_size_t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Plus_Bang",
"Hacl.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Bignum.Karatsuba.bn_karatsuba_res",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Subtraction_Dot",
"Hacl.Bignum.Addition.bn_sub_eq_len_u",
"Hacl.Bignum.Addition.bn_add_eq_len_u",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.Buffer.sub",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.op_Addition",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.append",
"Lib.Buffer.as_seq",
"Lib.Sequence.concat",
"Lib.Sequence.lemma_concat2",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let bn_karatsuba_last_sqr #t aLen tmp res =
| let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
let h = ST.get () in
LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c3 = bn_sub_eq_len_u aLen t01 t23 t45 in
let c5 = c2 -. c3 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c | false |
Test.Lowstarize.fst | Test.Lowstarize.mk_uint8 | val mk_uint8 (x: int) : Tac term | val mk_uint8 (x: int) : Tac term | let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit)) | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 24,
"start_col": 0,
"start_line": 22
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.int -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.term | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.int",
"FStar.Stubs.Tactics.V1.Builtins.pack",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.Stubs.Reflection.V1.Data.Tv_App",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.V1.Data.aqualv",
"Test.Lowstarize.mk_int",
"FStar.Stubs.Reflection.V1.Data.Q_Explicit",
"FStar.Stubs.Reflection.V1.Data.Tv_FVar",
"FStar.Stubs.Reflection.V1.Builtins.pack_fv",
"Prims.Cons",
"Prims.string",
"Prims.Nil"
] | [] | false | true | false | false | false | let mk_uint8 (x: int) : Tac term =
| pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar"; "UInt8"; "__uint_to_t"]))) (mk_int x, Q_Explicit)) | false |
Test.Lowstarize.fst | Test.Lowstarize.mk_uint32 | val mk_uint32 (x: int) : Tac term | val mk_uint32 (x: int) : Tac term | let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit)) | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 29,
"start_col": 0,
"start_line": 27
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: Prims.int -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.term | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.int",
"FStar.Stubs.Tactics.V1.Builtins.pack",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.Stubs.Reflection.V1.Data.Tv_App",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.V1.Data.aqualv",
"Test.Lowstarize.mk_int",
"FStar.Stubs.Reflection.V1.Data.Q_Explicit",
"FStar.Stubs.Reflection.V1.Data.Tv_FVar",
"FStar.Stubs.Reflection.V1.Builtins.pack_fv",
"Prims.Cons",
"Prims.string",
"Prims.Nil"
] | [] | false | true | false | false | false | let mk_uint32 (x: int) : Tac term =
| pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar"; "UInt32"; "__uint_to_t"]))) (mk_int x, Q_Explicit)) | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_last | val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres))) | val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres))) | let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 3,
"end_line": 184,
"start_col": 0,
"start_line": 169
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"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"
} | false |
aLen:
Lib.IntTypes.size_t
{ 4 * Lib.IntTypes.v aLen <= Lib.IntTypes.max_size_t /\ Lib.IntTypes.v aLen % 2 = 0 /\
0 < Lib.IntTypes.v aLen } ->
c0: Hacl.Spec.Bignum.Base.carry t ->
c1: Hacl.Spec.Bignum.Base.carry t ->
tmp: Hacl.Bignum.Definitions.lbignum t (4ul *! aLen) ->
res: Hacl.Bignum.Definitions.lbignum t (aLen +! aLen)
-> FStar.HyperStack.ST.Stack (Hacl.Bignum.Definitions.limb t) | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.max_size_t",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_LessThan",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Plus_Bang",
"Hacl.Bignum.Definitions.limb",
"Hacl.Bignum.Karatsuba.bn_karatsuba_res",
"Hacl.Bignum.Karatsuba.bn_middle_karatsuba",
"Hacl.Bignum.Addition.bn_add_eq_len_u",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.Buffer.sub",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Lib.Sequence.seq",
"Prims.l_or",
"Prims.nat",
"FStar.Seq.Base.length",
"Prims.op_Addition",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.append",
"Lib.Buffer.as_seq",
"Lib.Sequence.concat",
"Lib.Sequence.lemma_concat2",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let bn_karatsuba_last #t aLen c0 c1 tmp res =
| let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
let h = ST.get () in
LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c | false |
Test.Lowstarize.fst | Test.Lowstarize.is_string | val is_string : e: FStar.Stubs.Reflection.Types.term -> Prims.bool | let is_string e =
is_some (destruct_string e) | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 29,
"end_line": 54,
"start_col": 0,
"start_line": 53
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: FStar.Stubs.Reflection.Types.term -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Test.Lowstarize.is_some",
"Prims.string",
"Test.Lowstarize.destruct_string",
"Prims.bool"
] | [] | false | false | false | true | false | let is_string e =
| is_some (destruct_string e) | false |
|
Test.Lowstarize.fst | Test.Lowstarize.destruct_string | val destruct_string : e: FStar.Stubs.Reflection.Types.term -> FStar.Pervasives.Native.option Prims.string | let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 13,
"end_line": 47,
"start_col": 0,
"start_line": 44
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: FStar.Stubs.Reflection.Types.term -> FStar.Pervasives.Native.option Prims.string | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.V1.Builtins.inspect_ln",
"Prims.string",
"FStar.Pervasives.Native.Some",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option"
] | [] | false | false | false | true | false | let destruct_string e =
| match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None | false |
|
Test.Lowstarize.fst | Test.Lowstarize.mktuple_qns | val mktuple_qns : Prims.list (Prims.list Prims.string) | let mktuple_qns =
[ mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn;
mktuple7_qn; mktuple8_qn ] | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 93,
"start_col": 0,
"start_line": 91
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None
noextract
let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.list (Prims.list Prims.string) | Prims.Tot | [
"total"
] | [] | [
"Prims.Cons",
"Prims.list",
"Prims.string",
"FStar.Reflection.Const.mktuple2_qn",
"FStar.Reflection.Const.mktuple3_qn",
"FStar.Reflection.Const.mktuple4_qn",
"FStar.Reflection.Const.mktuple5_qn",
"FStar.Reflection.Const.mktuple6_qn",
"FStar.Reflection.Const.mktuple7_qn",
"FStar.Reflection.Const.mktuple8_qn",
"Prims.Nil"
] | [] | false | false | false | true | false | let mktuple_qns =
| [mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn; mktuple7_qn; mktuple8_qn] | false |
|
Test.Lowstarize.fst | Test.Lowstarize.gensym | val gensym : Type0 | let gensym = string * nat | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 146,
"start_col": 0,
"start_line": 146
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None
noextract
let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false
noextract
let mktuple_qns =
[ mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn;
mktuple7_qn; mktuple8_qn ]
noextract
let destruct_tuple (e: term): option (list term) =
let hd, args = collect_app_ln e in
match inspect_ln hd with
| Tv_UInst fv _
| Tv_FVar fv ->
if List.Tot.contains (inspect_fv fv) mktuple_qns then
Some (List.Tot.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []
) args)
else
None
| _ ->
None
noextract
let is_tuple (e: term) =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
List.Tot.contains (inspect_fv fv) mktuple_qns
| _ ->
false
noextract
let destruct_hex (e: term) =
let hd, tl = collect_app e in
if term_eq (`h) hd && List.Tot.length tl > 0 then begin
destruct_string (fst (List.Tot.hd tl))
end else
None
noextract
let is_hex e =
is_some (destruct_hex e)
// Main Tactic. This tactic fetches a top-level term and defines another,
// Low*-ized top-level term for it, where:
// - hex-encoded strings are lifted as top-level constant uint8 arrays
// - references to hex-encoded strings are replaced by a pair of the length
// of the corresponding array, and a reference to that array
// - lists are lifted as top-level arrays (using gcmalloc_of_list)
// - strings that are not marked as hex-encoded are lifted to C.String.t
// - tuples are traversed transparently
// - everything else is left as-is
//
// TODO: instead of pairs, use a dependent type that ties together an array and
// its length | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Prims.string",
"Prims.nat"
] | [] | false | false | false | true | true | let gensym =
| string * nat | false |
|
Test.Lowstarize.fst | Test.Lowstarize.is_hex | val is_hex : e: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool | let is_hex e =
is_some (destruct_hex e) | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 131,
"start_col": 0,
"start_line": 130
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None
noextract
let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false
noextract
let mktuple_qns =
[ mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn;
mktuple7_qn; mktuple8_qn ]
noextract
let destruct_tuple (e: term): option (list term) =
let hd, args = collect_app_ln e in
match inspect_ln hd with
| Tv_UInst fv _
| Tv_FVar fv ->
if List.Tot.contains (inspect_fv fv) mktuple_qns then
Some (List.Tot.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []
) args)
else
None
| _ ->
None
noextract
let is_tuple (e: term) =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
List.Tot.contains (inspect_fv fv) mktuple_qns
| _ ->
false
noextract
let destruct_hex (e: term) =
let hd, tl = collect_app e in
if term_eq (`h) hd && List.Tot.length tl > 0 then begin
destruct_string (fst (List.Tot.hd tl))
end else
None | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Test.Lowstarize.is_some",
"Prims.string",
"Prims.bool",
"FStar.Pervasives.Native.option",
"Test.Lowstarize.destruct_hex"
] | [] | false | true | false | false | false | let is_hex e =
| is_some (destruct_hex e) | false |
|
Test.Lowstarize.fst | Test.Lowstarize.lowstarize_string | val lowstarize_string (s: string) : Tac term | val lowstarize_string (s: string) : Tac term | let lowstarize_string (s: string): Tac term =
`(C.String.of_literal (`@s)) | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 195,
"start_col": 0,
"start_line": 194
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None
noextract
let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false
noextract
let mktuple_qns =
[ mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn;
mktuple7_qn; mktuple8_qn ]
noextract
let destruct_tuple (e: term): option (list term) =
let hd, args = collect_app_ln e in
match inspect_ln hd with
| Tv_UInst fv _
| Tv_FVar fv ->
if List.Tot.contains (inspect_fv fv) mktuple_qns then
Some (List.Tot.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []
) args)
else
None
| _ ->
None
noextract
let is_tuple (e: term) =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
List.Tot.contains (inspect_fv fv) mktuple_qns
| _ ->
false
noextract
let destruct_hex (e: term) =
let hd, tl = collect_app e in
if term_eq (`h) hd && List.Tot.length tl > 0 then begin
destruct_string (fst (List.Tot.hd tl))
end else
None
noextract
let is_hex e =
is_some (destruct_hex e)
// Main Tactic. This tactic fetches a top-level term and defines another,
// Low*-ized top-level term for it, where:
// - hex-encoded strings are lifted as top-level constant uint8 arrays
// - references to hex-encoded strings are replaced by a pair of the length
// of the corresponding array, and a reference to that array
// - lists are lifted as top-level arrays (using gcmalloc_of_list)
// - strings that are not marked as hex-encoded are lifted to C.String.t
// - tuples are traversed transparently
// - everything else is left as-is
//
// TODO: instead of pairs, use a dependent type that ties together an array and
// its length
let gensym = string * nat
noextract
let fresh (uniq: gensym): Tac (gensym * name) =
(fst uniq, snd uniq + 1), cur_module () @ [ fst uniq ^ string_of_int (snd uniq) ]
noeq
type lbuffer (a:Type0) =
| LB: len:UInt32.t -> b:B.buffer a{B.len b == len /\ B.recallable b} -> lbuffer a
noextract
let mk_gcmalloc_of_list (uniq: gensym) (arg: term) (l:int) (t: option term):
Tac (gensym * sigelt * term)
=
let def: term = pack (Tv_App
(pack (Tv_App (`LowStar.Buffer.gcmalloc_of_list) (`HS.root, Q_Explicit)))
(arg, Q_Explicit)
) in
let uniq, name = fresh uniq in
let fv: fv = pack_fv name in
let t: term = match t with None -> pack Tv_Unknown | Some t -> t in
let lb = pack_lb ({lb_fv = fv;
lb_us = [];
lb_typ = t;
lb_def = def}) in
let se: sigelt = pack_sigelt (Sg_Let false [lb]) in
uniq, se, mk_e_app (`LB) [mk_uint32 l; pack (Tv_FVar fv)]
noextract
let lowstarize_hex (uniq: gensym) (s: string): Tac (gensym * option sigelt * term) =
if String.length s % 2 <> 0
|| not (List.Tot.for_all is_hex_digit (String.list_of_string s)) then
fail ("Invalid hex string: " ^ s)
else
let constants = as_uint8s [] (String.list_of_string s) in
if String.length s = 0 then
let null = pack (Tv_App (`LowStar.Buffer.null) (`UInt8.t, Q_Implicit)) in
uniq, None, mk_e_app (`LB) [mk_uint32 0; null]
else
let l = normalize_term (String.length s / 2) in
let uniq, se, e = mk_gcmalloc_of_list uniq constants l None in
uniq, Some se, e
// Dependency analysis bug: does not go inside quotations (#1496)
module Whatever = C.String | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "C.String",
"short_module": "Whatever"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.string -> FStar.Tactics.Effect.Tac FStar.Stubs.Reflection.Types.term | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.string",
"FStar.Stubs.Reflection.Types.term"
] | [] | false | true | false | false | false | let lowstarize_string (s: string) : Tac term =
| `(C.String.of_literal (`@s)) | false |
Hacl.EC.Ed25519.fst | Hacl.EC.Ed25519.point_negate | val point_negate: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ disjoint out p /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == Spec.Ed25519.point_negate (F51.point_eval h0 p)) | val point_negate: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ disjoint out p /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == Spec.Ed25519.point_negate (F51.point_eval h0 p)) | let point_negate p out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_negate (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointNegate.point_negate p out | {
"file_name": "code/ed25519/Hacl.EC.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 50,
"end_line": 273,
"start_col": 0,
"start_line": 270
} | module Hacl.EC.Ed25519
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module F51 = Hacl.Impl.Ed25519.Field51
module SE = Spec.Ed25519
module SC = Spec.Curve25519
module ML = Hacl.Impl.Ed25519.Ladder
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
[@@ CPrologue
"/*******************************************************************************
Verified field arithmetic modulo p = 2^255 - 19.
This is a 64-bit optimized version, where a field element in radix-2^{51} is
represented as an array of five unsigned 64-bit integers, i.e., uint64_t[5].
*******************************************************************************/\n";
Comment "Write the additive identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_zero: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.zero)
let mk_felem_zero b =
Hacl.Bignum25519.make_zero b
[@@ Comment "Write the multiplicative identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_one: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.one)
let mk_felem_one b =
Hacl.Bignum25519.make_one b
[@@ Comment "Write `a + b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_add: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fadd (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_add a b out =
Hacl.Impl.Curve25519.Field51.fadd out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a - b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_sub: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fsub (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_sub a b out =
Hacl.Impl.Curve25519.Field51.fsub out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a * b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_mul: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_mul a b out =
push_frame();
let tmp = create 10ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fmul out a b tmp;
pop_frame()
[@@ Comment "Write `a * a mod p` in `out`.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are either disjoint or equal"]
val felem_sqr: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 a))
let felem_sqr a out =
push_frame();
let tmp = create 5ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fsqr out a tmp;
pop_frame()
[@@ Comment "Write `a ^ (p - 2) mod p` in `out`.
The function computes modular multiplicative inverse if `a` <> zero.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_inv: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\ disjoint a out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fpow (F51.fevalh h0 a) (SC.prime - 2))
let felem_inv a out =
Hacl.Bignum25519.inverse out a;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Load a little-endian field element from memory.
The argument `b` points to 32 bytes of valid memory, i.e., uint8_t[32].
The outparam `out` points to a field element of 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `b` and `out` are disjoint
NOTE that the function also performs the reduction modulo 2^255."]
val felem_load: b:lbuffer uint8 32ul -> out:F51.felem ->
Stack unit
(requires fun h -> live h b /\ live h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.as_nat h1 out == Lib.ByteSequence.nat_from_bytes_le (as_seq h0 b) % pow2 255)
let felem_load b out =
Hacl.Bignum25519.load_51 out b
[@@ Comment "Serialize a field element into little-endian memory.
The argument `a` points to a field element of 5 limbs in size, i.e., uint64_t[5].
The outparam `out` points to 32 bytes of valid memory, i.e., uint8_t[32].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_store: a:F51.felem -> out:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Lib.ByteSequence.nat_to_bytes_le 32 (F51.fevalh h0 a))
let felem_store a out =
Hacl.Bignum25519.store_51 out a
[@@ CPrologue
"/*******************************************************************************
Verified group operations for the edwards25519 elliptic curve of the form
−x^2 + y^2 = 1 − (121665/121666) * x^2 * y^2.
This is a 64-bit optimized version, where a group element in extended homogeneous
coordinates (X, Y, Z, T) is represented as an array of 20 unsigned 64-bit
integers, i.e., uint64_t[20].
*******************************************************************************/\n";
Comment "Write the point at infinity (additive identity) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_point_at_inf: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_point_at_infinity)
let mk_point_at_inf p =
Hacl.Impl.Ed25519.PointConstants.make_point_inf p
[@@ Comment "Write the base point (generator) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_base_point: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_g)
let mk_base_point p =
Spec.Ed25519.Lemmas.g_is_on_curve ();
Hacl.Impl.Ed25519.PointConstants.make_g p
[@@ Comment "Write `-p` in `out` (point negation).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are disjoint"]
val point_negate: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ disjoint out p /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == Spec.Ed25519.point_negate (F51.point_eval h0 p)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.PointNegate.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDouble.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.PointConstants.fst.checked",
"Hacl.Impl.Ed25519.PointCompress.fst.checked",
"Hacl.Impl.Ed25519.PointAdd.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Impl.Curve25519.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.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.EC.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "ML"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"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.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Hacl.Impl.Ed25519.Field51.point -> out: Hacl.Impl.Ed25519.Field51.point
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Ed25519.Field51.point",
"Hacl.Impl.Ed25519.PointNegate.point_negate",
"Prims.unit",
"Spec.Ed25519.Lemmas.to_aff_point_negate",
"Hacl.Impl.Ed25519.Field51.refl_ext_point",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint64",
"FStar.UInt32.__uint_to_t",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let point_negate p out =
| let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_negate (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointNegate.point_negate p out | false |
Test.Lowstarize.fst | Test.Lowstarize.must | val must (x: option 'a) : Tac 'a | val must (x: option 'a) : Tac 'a | let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must" | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 23,
"end_line": 60,
"start_col": 0,
"start_line": 57
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.Pervasives.Native.option 'a -> FStar.Tactics.Effect.Tac 'a | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Pervasives.Native.option",
"FStar.Tactics.V1.Derived.fail"
] | [] | false | true | false | false | false | let must (x: option 'a) : Tac 'a =
| match x with
| Some x -> x
| None -> fail "must" | false |
Test.Lowstarize.fst | Test.Lowstarize.is_some | val is_some : _: FStar.Pervasives.Native.option _ -> Prims.bool | let is_some = function Some _ -> true | None -> false | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 53,
"end_line": 50,
"start_col": 0,
"start_line": 50
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: FStar.Pervasives.Native.option _ -> Prims.bool | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.Native.option",
"Prims.bool"
] | [] | false | false | false | true | false | let is_some =
| function
| Some _ -> true
| None -> false | false |
|
Test.Lowstarize.fst | Test.Lowstarize.destruct_tuple | val destruct_tuple (e: term) : option (list term) | val destruct_tuple (e: term) : option (list term) | let destruct_tuple (e: term): option (list term) =
let hd, args = collect_app_ln e in
match inspect_ln hd with
| Tv_UInst fv _
| Tv_FVar fv ->
if List.Tot.contains (inspect_fv fv) mktuple_qns then
Some (List.Tot.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []
) args)
else
None
| _ ->
None | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 110,
"start_col": 0,
"start_line": 96
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None
noextract
let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false
noextract
let mktuple_qns =
[ mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn;
mktuple7_qn; mktuple8_qn ] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: FStar.Stubs.Reflection.Types.term
-> FStar.Pervasives.Native.option (Prims.list FStar.Stubs.Reflection.Types.term) | Prims.Tot | [
"total"
] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Prims.list",
"FStar.Stubs.Reflection.V1.Data.argv",
"FStar.Stubs.Reflection.V1.Builtins.inspect_ln",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.V1.Data.universes",
"FStar.List.Tot.Base.contains",
"Prims.string",
"FStar.Stubs.Reflection.V1.Builtins.inspect_fv",
"Test.Lowstarize.mktuple_qns",
"FStar.Pervasives.Native.Some",
"FStar.List.Tot.Base.concatMap",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Reflection.V1.Data.aqualv",
"Prims.Cons",
"Prims.Nil",
"Prims.bool",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.Reflection.V1.Derived.collect_app_ln"
] | [] | false | false | false | true | false | let destruct_tuple (e: term) : option (list term) =
| let hd, args = collect_app_ln e in
match inspect_ln hd with
| Tv_UInst fv _
| Tv_FVar fv ->
if List.Tot.contains (inspect_fv fv) mktuple_qns
then
Some
(List.Tot.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> [])
args)
else None
| _ -> None | false |
Test.Lowstarize.fst | Test.Lowstarize.is_list | val is_list : e: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool | let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 88,
"start_col": 0,
"start_line": 82
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.V1.Data.universes",
"Prims.op_BarBar",
"Prims.op_Equality",
"Prims.list",
"Prims.string",
"FStar.Stubs.Reflection.V1.Builtins.inspect_fv",
"FStar.Reflection.Const.nil_qn",
"FStar.Reflection.Const.cons_qn",
"FStar.Stubs.Reflection.V1.Data.term_view",
"Prims.bool",
"FStar.Stubs.Tactics.V1.Builtins.inspect",
"FStar.Pervasives.Native.fst",
"FStar.Stubs.Reflection.V1.Data.argv",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V1.SyntaxHelpers.collect_app"
] | [] | false | true | false | false | false | let is_list e =
| match inspect (fst (collect_app e)) with
| Tv_UInst fv _ | Tv_FVar fv -> inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ -> false | false |
|
Test.Lowstarize.fst | Test.Lowstarize.fresh | val fresh (uniq: gensym) : Tac (gensym * name) | val fresh (uniq: gensym) : Tac (gensym * name) | let fresh (uniq: gensym): Tac (gensym * name) =
(fst uniq, snd uniq + 1), cur_module () @ [ fst uniq ^ string_of_int (snd uniq) ] | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 83,
"end_line": 150,
"start_col": 0,
"start_line": 149
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None
noextract
let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false
noextract
let mktuple_qns =
[ mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn;
mktuple7_qn; mktuple8_qn ]
noextract
let destruct_tuple (e: term): option (list term) =
let hd, args = collect_app_ln e in
match inspect_ln hd with
| Tv_UInst fv _
| Tv_FVar fv ->
if List.Tot.contains (inspect_fv fv) mktuple_qns then
Some (List.Tot.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []
) args)
else
None
| _ ->
None
noextract
let is_tuple (e: term) =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
List.Tot.contains (inspect_fv fv) mktuple_qns
| _ ->
false
noextract
let destruct_hex (e: term) =
let hd, tl = collect_app e in
if term_eq (`h) hd && List.Tot.length tl > 0 then begin
destruct_string (fst (List.Tot.hd tl))
end else
None
noextract
let is_hex e =
is_some (destruct_hex e)
// Main Tactic. This tactic fetches a top-level term and defines another,
// Low*-ized top-level term for it, where:
// - hex-encoded strings are lifted as top-level constant uint8 arrays
// - references to hex-encoded strings are replaced by a pair of the length
// of the corresponding array, and a reference to that array
// - lists are lifted as top-level arrays (using gcmalloc_of_list)
// - strings that are not marked as hex-encoded are lifted to C.String.t
// - tuples are traversed transparently
// - everything else is left as-is
//
// TODO: instead of pairs, use a dependent type that ties together an array and
// its length
let gensym = string * nat | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | uniq: Test.Lowstarize.gensym
-> FStar.Tactics.Effect.Tac (Test.Lowstarize.gensym * FStar.Stubs.Reflection.Types.name) | FStar.Tactics.Effect.Tac | [] | [] | [
"Test.Lowstarize.gensym",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.Types.name",
"Prims.string",
"Prims.nat",
"FStar.Pervasives.Native.fst",
"Prims.op_Addition",
"FStar.Pervasives.Native.snd",
"FStar.Pervasives.Native.tuple2",
"FStar.List.Tot.Base.op_At",
"Prims.Cons",
"Prims.op_Hat",
"Prims.string_of_int",
"Prims.Nil",
"Prims.list",
"FStar.Tactics.V1.Derived.cur_module"
] | [] | false | true | false | false | false | let fresh (uniq: gensym) : Tac (gensym * name) =
| (fst uniq, snd uniq + 1), cur_module () @ [fst uniq ^ string_of_int (snd uniq)] | false |
Test.Lowstarize.fst | Test.Lowstarize.lowstarize_hex | val lowstarize_hex (uniq: gensym) (s: string) : Tac (gensym * option sigelt * term) | val lowstarize_hex (uniq: gensym) (s: string) : Tac (gensym * option sigelt * term) | let lowstarize_hex (uniq: gensym) (s: string): Tac (gensym * option sigelt * term) =
if String.length s % 2 <> 0
|| not (List.Tot.for_all is_hex_digit (String.list_of_string s)) then
fail ("Invalid hex string: " ^ s)
else
let constants = as_uint8s [] (String.list_of_string s) in
if String.length s = 0 then
let null = pack (Tv_App (`LowStar.Buffer.null) (`UInt8.t, Q_Implicit)) in
uniq, None, mk_e_app (`LB) [mk_uint32 0; null]
else
let l = normalize_term (String.length s / 2) in
let uniq, se, e = mk_gcmalloc_of_list uniq constants l None in
uniq, Some se, e | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 187,
"start_col": 0,
"start_line": 175
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None
noextract
let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false
noextract
let mktuple_qns =
[ mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn;
mktuple7_qn; mktuple8_qn ]
noextract
let destruct_tuple (e: term): option (list term) =
let hd, args = collect_app_ln e in
match inspect_ln hd with
| Tv_UInst fv _
| Tv_FVar fv ->
if List.Tot.contains (inspect_fv fv) mktuple_qns then
Some (List.Tot.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []
) args)
else
None
| _ ->
None
noextract
let is_tuple (e: term) =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
List.Tot.contains (inspect_fv fv) mktuple_qns
| _ ->
false
noextract
let destruct_hex (e: term) =
let hd, tl = collect_app e in
if term_eq (`h) hd && List.Tot.length tl > 0 then begin
destruct_string (fst (List.Tot.hd tl))
end else
None
noextract
let is_hex e =
is_some (destruct_hex e)
// Main Tactic. This tactic fetches a top-level term and defines another,
// Low*-ized top-level term for it, where:
// - hex-encoded strings are lifted as top-level constant uint8 arrays
// - references to hex-encoded strings are replaced by a pair of the length
// of the corresponding array, and a reference to that array
// - lists are lifted as top-level arrays (using gcmalloc_of_list)
// - strings that are not marked as hex-encoded are lifted to C.String.t
// - tuples are traversed transparently
// - everything else is left as-is
//
// TODO: instead of pairs, use a dependent type that ties together an array and
// its length
let gensym = string * nat
noextract
let fresh (uniq: gensym): Tac (gensym * name) =
(fst uniq, snd uniq + 1), cur_module () @ [ fst uniq ^ string_of_int (snd uniq) ]
noeq
type lbuffer (a:Type0) =
| LB: len:UInt32.t -> b:B.buffer a{B.len b == len /\ B.recallable b} -> lbuffer a
noextract
let mk_gcmalloc_of_list (uniq: gensym) (arg: term) (l:int) (t: option term):
Tac (gensym * sigelt * term)
=
let def: term = pack (Tv_App
(pack (Tv_App (`LowStar.Buffer.gcmalloc_of_list) (`HS.root, Q_Explicit)))
(arg, Q_Explicit)
) in
let uniq, name = fresh uniq in
let fv: fv = pack_fv name in
let t: term = match t with None -> pack Tv_Unknown | Some t -> t in
let lb = pack_lb ({lb_fv = fv;
lb_us = [];
lb_typ = t;
lb_def = def}) in
let se: sigelt = pack_sigelt (Sg_Let false [lb]) in
uniq, se, mk_e_app (`LB) [mk_uint32 l; pack (Tv_FVar fv)] | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | uniq: Test.Lowstarize.gensym -> s: Prims.string
-> FStar.Tactics.Effect.Tac
((Test.Lowstarize.gensym * FStar.Pervasives.Native.option FStar.Stubs.Reflection.Types.sigelt) *
FStar.Stubs.Reflection.Types.term) | FStar.Tactics.Effect.Tac | [] | [] | [
"Test.Lowstarize.gensym",
"Prims.string",
"Prims.op_BarBar",
"Prims.op_disEquality",
"Prims.int",
"Prims.op_Modulus",
"FStar.String.length",
"Prims.op_Negation",
"FStar.List.Tot.Base.for_all",
"FStar.String.char",
"Lib.Meta.is_hex_digit",
"FStar.String.list_of_string",
"FStar.Tactics.V1.Derived.fail",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.Types.sigelt",
"FStar.Stubs.Reflection.Types.term",
"Prims.op_Hat",
"Prims.bool",
"Prims.op_Equality",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Pervasives.Native.None",
"FStar.Reflection.V1.Derived.mk_e_app",
"Prims.list",
"Prims.Cons",
"Prims.Nil",
"Test.Lowstarize.mk_uint32",
"FStar.Stubs.Tactics.V1.Builtins.pack",
"FStar.Stubs.Reflection.V1.Data.Tv_App",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.V1.Data.aqualv",
"FStar.Stubs.Reflection.V1.Data.Q_Implicit",
"FStar.Pervasives.Native.Some",
"Test.Lowstarize.mk_gcmalloc_of_list",
"FStar.Pervasives.normalize_term",
"Prims.op_Division",
"Test.Lowstarize.as_uint8s"
] | [] | false | true | false | false | false | let lowstarize_hex (uniq: gensym) (s: string) : Tac (gensym * option sigelt * term) =
| if String.length s % 2 <> 0 || not (List.Tot.for_all is_hex_digit (String.list_of_string s))
then fail ("Invalid hex string: " ^ s)
else
let constants = as_uint8s [] (String.list_of_string s) in
if String.length s = 0
then
let null = pack (Tv_App (`LowStar.Buffer.null) ((`UInt8.t), Q_Implicit)) in
uniq, None, mk_e_app (`LB) [mk_uint32 0; null]
else
let l = normalize_term (String.length s / 2) in
let uniq, se, e = mk_gcmalloc_of_list uniq constants l None in
uniq, Some se, e | false |
Test.Lowstarize.fst | Test.Lowstarize.mk_gcmalloc_of_list | val mk_gcmalloc_of_list (uniq: gensym) (arg: term) (l: int) (t: option term)
: Tac (gensym * sigelt * term) | val mk_gcmalloc_of_list (uniq: gensym) (arg: term) (l: int) (t: option term)
: Tac (gensym * sigelt * term) | let mk_gcmalloc_of_list (uniq: gensym) (arg: term) (l:int) (t: option term):
Tac (gensym * sigelt * term)
=
let def: term = pack (Tv_App
(pack (Tv_App (`LowStar.Buffer.gcmalloc_of_list) (`HS.root, Q_Explicit)))
(arg, Q_Explicit)
) in
let uniq, name = fresh uniq in
let fv: fv = pack_fv name in
let t: term = match t with None -> pack Tv_Unknown | Some t -> t in
let lb = pack_lb ({lb_fv = fv;
lb_us = [];
lb_typ = t;
lb_def = def}) in
let se: sigelt = pack_sigelt (Sg_Let false [lb]) in
uniq, se, mk_e_app (`LB) [mk_uint32 l; pack (Tv_FVar fv)] | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 59,
"end_line": 172,
"start_col": 0,
"start_line": 157
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None
noextract
let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false
noextract
let mktuple_qns =
[ mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn;
mktuple7_qn; mktuple8_qn ]
noextract
let destruct_tuple (e: term): option (list term) =
let hd, args = collect_app_ln e in
match inspect_ln hd with
| Tv_UInst fv _
| Tv_FVar fv ->
if List.Tot.contains (inspect_fv fv) mktuple_qns then
Some (List.Tot.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []
) args)
else
None
| _ ->
None
noextract
let is_tuple (e: term) =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
List.Tot.contains (inspect_fv fv) mktuple_qns
| _ ->
false
noextract
let destruct_hex (e: term) =
let hd, tl = collect_app e in
if term_eq (`h) hd && List.Tot.length tl > 0 then begin
destruct_string (fst (List.Tot.hd tl))
end else
None
noextract
let is_hex e =
is_some (destruct_hex e)
// Main Tactic. This tactic fetches a top-level term and defines another,
// Low*-ized top-level term for it, where:
// - hex-encoded strings are lifted as top-level constant uint8 arrays
// - references to hex-encoded strings are replaced by a pair of the length
// of the corresponding array, and a reference to that array
// - lists are lifted as top-level arrays (using gcmalloc_of_list)
// - strings that are not marked as hex-encoded are lifted to C.String.t
// - tuples are traversed transparently
// - everything else is left as-is
//
// TODO: instead of pairs, use a dependent type that ties together an array and
// its length
let gensym = string * nat
noextract
let fresh (uniq: gensym): Tac (gensym * name) =
(fst uniq, snd uniq + 1), cur_module () @ [ fst uniq ^ string_of_int (snd uniq) ]
noeq
type lbuffer (a:Type0) =
| LB: len:UInt32.t -> b:B.buffer a{B.len b == len /\ B.recallable b} -> lbuffer a | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
uniq: Test.Lowstarize.gensym ->
arg: FStar.Stubs.Reflection.Types.term ->
l: Prims.int ->
t: FStar.Pervasives.Native.option FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
((Test.Lowstarize.gensym * FStar.Stubs.Reflection.Types.sigelt) *
FStar.Stubs.Reflection.Types.term) | FStar.Tactics.Effect.Tac | [] | [] | [
"Test.Lowstarize.gensym",
"FStar.Stubs.Reflection.Types.term",
"Prims.int",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.Types.name",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Stubs.Reflection.Types.sigelt",
"FStar.Pervasives.Native.tuple3",
"FStar.Reflection.V1.Derived.mk_e_app",
"Prims.list",
"Prims.Cons",
"Prims.Nil",
"FStar.Stubs.Tactics.V1.Builtins.pack",
"FStar.Stubs.Reflection.V1.Data.Tv_FVar",
"Test.Lowstarize.mk_uint32",
"FStar.Stubs.Reflection.V1.Builtins.pack_sigelt",
"FStar.Stubs.Reflection.V1.Data.Sg_Let",
"FStar.Stubs.Reflection.Types.letbinding",
"FStar.Stubs.Reflection.V1.Builtins.pack_lb",
"FStar.Stubs.Reflection.V1.Data.Mklb_view",
"FStar.Stubs.Reflection.V1.Data.univ_name",
"FStar.Stubs.Reflection.V1.Data.Tv_Unknown",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.V1.Builtins.pack_fv",
"FStar.Pervasives.Native.tuple2",
"Test.Lowstarize.fresh",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.Stubs.Reflection.V1.Data.Tv_App",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.V1.Data.aqualv",
"FStar.Stubs.Reflection.V1.Data.Q_Explicit"
] | [] | false | true | false | false | false | let mk_gcmalloc_of_list (uniq: gensym) (arg: term) (l: int) (t: option term)
: Tac (gensym * sigelt * term) =
| let def:term =
pack (Tv_App (pack (Tv_App (`LowStar.Buffer.gcmalloc_of_list) ((`HS.root), Q_Explicit)))
(arg, Q_Explicit))
in
let uniq, name = fresh uniq in
let fv:fv = pack_fv name in
let t:term =
match t with
| None -> pack Tv_Unknown
| Some t -> t
in
let lb = pack_lb ({ lb_fv = fv; lb_us = []; lb_typ = t; lb_def = def }) in
let se:sigelt = pack_sigelt (Sg_Let false [lb]) in
uniq, se, mk_e_app (`LB) [mk_uint32 l; pack (Tv_FVar fv)] | false |
Test.Lowstarize.fst | Test.Lowstarize.is_tuple | val is_tuple : e: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool | let is_tuple (e: term) =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
List.Tot.contains (inspect_fv fv) mktuple_qns
| _ ->
false | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 11,
"end_line": 119,
"start_col": 0,
"start_line": 113
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None
noextract
let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false
noextract
let mktuple_qns =
[ mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn;
mktuple7_qn; mktuple8_qn ]
noextract
let destruct_tuple (e: term): option (list term) =
let hd, args = collect_app_ln e in
match inspect_ln hd with
| Tv_UInst fv _
| Tv_FVar fv ->
if List.Tot.contains (inspect_fv fv) mktuple_qns then
Some (List.Tot.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []
) args)
else
None
| _ ->
None | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: FStar.Stubs.Reflection.Types.term -> FStar.Tactics.Effect.Tac Prims.bool | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.V1.Data.universes",
"FStar.List.Tot.Base.contains",
"Prims.list",
"Prims.string",
"FStar.Stubs.Reflection.V1.Builtins.inspect_fv",
"Test.Lowstarize.mktuple_qns",
"FStar.Stubs.Reflection.V1.Data.term_view",
"Prims.bool",
"FStar.Stubs.Tactics.V1.Builtins.inspect",
"FStar.Pervasives.Native.fst",
"FStar.Stubs.Reflection.V1.Data.argv",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V1.SyntaxHelpers.collect_app"
] | [] | false | true | false | false | false | let is_tuple (e: term) =
| match inspect (fst (collect_app e)) with
| Tv_UInst fv _ | Tv_FVar fv -> List.Tot.contains (inspect_fv fv) mktuple_qns
| _ -> false | false |
|
Test.Lowstarize.fst | Test.Lowstarize.destruct_list | val destruct_list (e: term) : Tac (option (list term)) | val destruct_list (e: term) : Tac (option (list term)) | let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 79,
"start_col": 0,
"start_line": 63
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.Native.option (Prims.list FStar.Stubs.Reflection.Types.term)) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Prims.list",
"FStar.Stubs.Reflection.V1.Data.argv",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Stubs.Reflection.V1.Data.term_view",
"FStar.Pervasives.Native.tuple2",
"FStar.Stubs.Reflection.V1.Data.aqualv",
"FStar.Stubs.Reflection.V1.Builtins.inspect_ln",
"FStar.Stubs.Reflection.Types.fv",
"FStar.Stubs.Reflection.V1.Data.universes",
"Prims.op_Equality",
"Prims.string",
"FStar.Stubs.Reflection.V1.Builtins.inspect_fv",
"FStar.Reflection.Const.cons_qn",
"FStar.Pervasives.Native.Some",
"FStar.Pervasives.Native.option",
"Prims.Cons",
"Test.Lowstarize.must",
"Test.Lowstarize.destruct_list",
"Prims.bool",
"FStar.Pervasives.Native.None",
"FStar.Reflection.Const.nil_qn",
"Prims.Nil",
"FStar.Tactics.V1.SyntaxHelpers.collect_app"
] | [
"recursion"
] | false | true | false | false | false | let rec destruct_list (e: term) : Tac (option (list term)) =
| let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [_ ; hd, _ ; tl, _]
| Tv_FVar fv, [_ ; hd, _ ; tl, _] ->
if inspect_fv fv = cons_qn then Some (hd :: must (destruct_list tl)) else None
| Tv_UInst fv _, _ | Tv_FVar fv, _ -> if inspect_fv fv = nil_qn then Some [] else None
| _ -> None | false |
Test.Lowstarize.fst | Test.Lowstarize.destruct_hex | val destruct_hex : e: FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option Prims.string) | let destruct_hex (e: term) =
let hd, tl = collect_app e in
if term_eq (`h) hd && List.Tot.length tl > 0 then begin
destruct_string (fst (List.Tot.hd tl))
end else
None | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 127,
"start_col": 0,
"start_line": 122
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None
noextract
let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false
noextract
let mktuple_qns =
[ mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn;
mktuple7_qn; mktuple8_qn ]
noextract
let destruct_tuple (e: term): option (list term) =
let hd, args = collect_app_ln e in
match inspect_ln hd with
| Tv_UInst fv _
| Tv_FVar fv ->
if List.Tot.contains (inspect_fv fv) mktuple_qns then
Some (List.Tot.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []
) args)
else
None
| _ ->
None
noextract
let is_tuple (e: term) =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
List.Tot.contains (inspect_fv fv) mktuple_qns
| _ ->
false | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | e: FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option Prims.string) | FStar.Tactics.Effect.Tac | [] | [] | [
"FStar.Stubs.Reflection.Types.term",
"Prims.list",
"FStar.Stubs.Reflection.V1.Data.argv",
"Prims.op_AmpAmp",
"FStar.Stubs.Reflection.V1.Builtins.term_eq",
"Prims.op_GreaterThan",
"FStar.List.Tot.Base.length",
"Test.Lowstarize.destruct_string",
"FStar.Pervasives.Native.fst",
"FStar.Stubs.Reflection.V1.Data.aqualv",
"FStar.List.Tot.Base.hd",
"Prims.bool",
"FStar.Pervasives.Native.None",
"Prims.string",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"FStar.Tactics.V1.SyntaxHelpers.collect_app"
] | [] | false | true | false | false | false | let destruct_hex (e: term) =
| let hd, tl = collect_app e in
if term_eq (`h) hd && List.Tot.length tl > 0 then destruct_string (fst (List.Tot.hd tl)) else None | false |
|
Hacl.EC.Ed25519.fst | Hacl.EC.Ed25519.point_add | val point_add: p:F51.point -> q:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ live h q /\
eq_or_disjoint p q /\
eq_or_disjoint p out /\ eq_or_disjoint q out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p) /\
F51.point_inv_t h q /\ F51.inv_ext_point (as_seq h q))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out ==
SE.point_add (F51.point_eval h0 p) (F51.point_eval h0 q)) | val point_add: p:F51.point -> q:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ live h q /\
eq_or_disjoint p q /\
eq_or_disjoint p out /\ eq_or_disjoint q out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p) /\
F51.point_inv_t h q /\ F51.inv_ext_point (as_seq h q))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out ==
SE.point_add (F51.point_eval h0 p) (F51.point_eval h0 q)) | let point_add p q out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_add_lemma
(F51.refl_ext_point (as_seq h0 p))
(F51.refl_ext_point (as_seq h0 q));
Hacl.Impl.Ed25519.PointAdd.point_add out p q | {
"file_name": "code/ed25519/Hacl.EC.Ed25519.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 301,
"start_col": 0,
"start_line": 296
} | module Hacl.EC.Ed25519
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
module ST = FStar.HyperStack.ST
module F51 = Hacl.Impl.Ed25519.Field51
module SE = Spec.Ed25519
module SC = Spec.Curve25519
module ML = Hacl.Impl.Ed25519.Ladder
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
[@@ CPrologue
"/*******************************************************************************
Verified field arithmetic modulo p = 2^255 - 19.
This is a 64-bit optimized version, where a field element in radix-2^{51} is
represented as an array of five unsigned 64-bit integers, i.e., uint64_t[5].
*******************************************************************************/\n";
Comment "Write the additive identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_zero: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.zero)
let mk_felem_zero b =
Hacl.Bignum25519.make_zero b
[@@ Comment "Write the multiplicative identity in `f`.
The outparam `f` is meant to be 5 limbs in size, i.e., uint64_t[5]."]
val mk_felem_one: b:F51.felem ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 -> modifies (loc b) h0 h1 /\
F51.mul_inv_t h1 b /\
F51.fevalh h1 b == SC.one)
let mk_felem_one b =
Hacl.Bignum25519.make_one b
[@@ Comment "Write `a + b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_add: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fadd (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_add a b out =
Hacl.Impl.Curve25519.Field51.fadd out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a - b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_sub: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
(disjoint out a \/ out == a) /\
(disjoint out b \/ out == b) /\
(disjoint a b \/ a == b) /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fsub (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_sub a b out =
Hacl.Impl.Curve25519.Field51.fsub out a b;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Write `a * b mod p` in `out`.
The arguments `a`, `b`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a`, `b`, and `out` are either pairwise disjoint or equal"]
val felem_mul: a:F51.felem -> b:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h out /\
F51.mul_inv_t h a /\
F51.mul_inv_t h b)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 b))
let felem_mul a b out =
push_frame();
let tmp = create 10ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fmul out a b tmp;
pop_frame()
[@@ Comment "Write `a * a mod p` in `out`.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are either disjoint or equal"]
val felem_sqr: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fmul (F51.fevalh h0 a) (F51.fevalh h0 a))
let felem_sqr a out =
push_frame();
let tmp = create 5ul (u128 0) in
Hacl.Impl.Curve25519.Field51.fsqr out a tmp;
pop_frame()
[@@ Comment "Write `a ^ (p - 2) mod p` in `out`.
The function computes modular multiplicative inverse if `a` <> zero.
The argument `a`, and the outparam `out` are meant to be 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_inv: a:F51.felem -> out:F51.felem ->
Stack unit
(requires fun h ->
live h a /\ live h out /\ disjoint a out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.fevalh h1 out == SC.fpow (F51.fevalh h0 a) (SC.prime - 2))
let felem_inv a out =
Hacl.Bignum25519.inverse out a;
Hacl.Bignum25519.reduce_513 out
[@@ Comment "Load a little-endian field element from memory.
The argument `b` points to 32 bytes of valid memory, i.e., uint8_t[32].
The outparam `out` points to a field element of 5 limbs in size, i.e., uint64_t[5].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `b` and `out` are disjoint
NOTE that the function also performs the reduction modulo 2^255."]
val felem_load: b:lbuffer uint8 32ul -> out:F51.felem ->
Stack unit
(requires fun h -> live h b /\ live h out)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.mul_inv_t h1 out /\
F51.as_nat h1 out == Lib.ByteSequence.nat_from_bytes_le (as_seq h0 b) % pow2 255)
let felem_load b out =
Hacl.Bignum25519.load_51 out b
[@@ Comment "Serialize a field element into little-endian memory.
The argument `a` points to a field element of 5 limbs in size, i.e., uint64_t[5].
The outparam `out` points to 32 bytes of valid memory, i.e., uint8_t[32].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `a` and `out` are disjoint"]
val felem_store: a:F51.felem -> out:lbuffer uint8 32ul ->
Stack unit
(requires fun h ->
live h a /\ live h out /\
F51.mul_inv_t h a)
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
as_seq h1 out == Lib.ByteSequence.nat_to_bytes_le 32 (F51.fevalh h0 a))
let felem_store a out =
Hacl.Bignum25519.store_51 out a
[@@ CPrologue
"/*******************************************************************************
Verified group operations for the edwards25519 elliptic curve of the form
−x^2 + y^2 = 1 − (121665/121666) * x^2 * y^2.
This is a 64-bit optimized version, where a group element in extended homogeneous
coordinates (X, Y, Z, T) is represented as an array of 20 unsigned 64-bit
integers, i.e., uint64_t[20].
*******************************************************************************/\n";
Comment "Write the point at infinity (additive identity) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_point_at_inf: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_point_at_infinity)
let mk_point_at_inf p =
Hacl.Impl.Ed25519.PointConstants.make_point_inf p
[@@ Comment "Write the base point (generator) in `p`.
The outparam `p` is meant to be 20 limbs in size, i.e., uint64_t[20]."]
val mk_base_point: p:F51.point ->
Stack unit
(requires fun h -> live h p)
(ensures fun h0 _ h1 -> modifies (loc p) h0 h1 /\
F51.point_inv_t h1 p /\ F51.inv_ext_point (as_seq h1 p) /\
SE.to_aff_point (F51.point_eval h1 p) == SE.aff_g)
let mk_base_point p =
Spec.Ed25519.Lemmas.g_is_on_curve ();
Hacl.Impl.Ed25519.PointConstants.make_g p
[@@ Comment "Write `-p` in `out` (point negation).
The argument `p` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p` and `out` are disjoint"]
val point_negate: p:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ disjoint out p /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out == Spec.Ed25519.point_negate (F51.point_eval h0 p))
let point_negate p out =
let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_negate (F51.refl_ext_point (as_seq h0 p));
Hacl.Impl.Ed25519.PointNegate.point_negate p out
[@@ Comment "Write `p + q` in `out` (point addition).
The arguments `p`, `q` and the outparam `out` are meant to be 20 limbs in size, i.e., uint64_t[20].
Before calling this function, the caller will need to ensure that the following
precondition is observed.
• `p`, `q`, and `out` are either pairwise disjoint or equal"]
val point_add: p:F51.point -> q:F51.point -> out:F51.point ->
Stack unit
(requires fun h ->
live h out /\ live h p /\ live h q /\
eq_or_disjoint p q /\
eq_or_disjoint p out /\ eq_or_disjoint q out /\
F51.point_inv_t h p /\ F51.inv_ext_point (as_seq h p) /\
F51.point_inv_t h q /\ F51.inv_ext_point (as_seq h q))
(ensures fun h0 _ h1 -> modifies (loc out) h0 h1 /\
F51.point_inv_t h1 out /\ F51.inv_ext_point (as_seq h1 out) /\
F51.point_eval h1 out ==
SE.point_add (F51.point_eval h0 p) (F51.point_eval h0 q)) | {
"checked_file": "/",
"dependencies": [
"Spec.Ed25519.Lemmas.fsti.checked",
"Spec.Ed25519.fst.checked",
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Ed25519.PointNegate.fst.checked",
"Hacl.Impl.Ed25519.PointEqual.fst.checked",
"Hacl.Impl.Ed25519.PointDouble.fst.checked",
"Hacl.Impl.Ed25519.PointDecompress.fst.checked",
"Hacl.Impl.Ed25519.PointConstants.fst.checked",
"Hacl.Impl.Ed25519.PointCompress.fst.checked",
"Hacl.Impl.Ed25519.PointAdd.fst.checked",
"Hacl.Impl.Ed25519.Ladder.fsti.checked",
"Hacl.Impl.Ed25519.Field51.fst.checked",
"Hacl.Impl.Curve25519.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.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.EC.Ed25519.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Ladder",
"short_module": "ML"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "SC"
},
{
"abbrev": true,
"full_module": "Spec.Ed25519",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Ed25519.Field51",
"short_module": "F51"
},
{
"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.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.EC",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
p: Hacl.Impl.Ed25519.Field51.point ->
q: Hacl.Impl.Ed25519.Field51.point ->
out: Hacl.Impl.Ed25519.Field51.point
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Ed25519.Field51.point",
"Hacl.Impl.Ed25519.PointAdd.point_add",
"Prims.unit",
"Spec.Ed25519.Lemmas.to_aff_point_add_lemma",
"Hacl.Impl.Ed25519.Field51.refl_ext_point",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Lib.IntTypes.uint64",
"FStar.UInt32.__uint_to_t",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let point_add p q out =
| let h0 = ST.get () in
Spec.Ed25519.Lemmas.to_aff_point_add_lemma (F51.refl_ext_point (as_seq h0 p))
(F51.refl_ext_point (as_seq h0 q));
Hacl.Impl.Ed25519.PointAdd.point_add out p q | false |
Test.Lowstarize.fst | Test.Lowstarize.lowstarize_expr | val lowstarize_expr (uniq: gensym) (e: term) : Tac (gensym * list sigelt * term) | val lowstarize_expr (uniq: gensym) (e: term) : Tac (gensym * list sigelt * term) | let rec lowstarize_expr (uniq: gensym) (e: term): Tac (gensym * list sigelt * term) =
let e = norm_term [ delta; zeta; iota; primops ] e in
if is_hex e then
let uniq, se, e = lowstarize_hex uniq (must (destruct_hex e)) in
match se with
| None -> uniq, [], e
| Some se -> uniq, [se], e
else if is_string e then
uniq, [], lowstarize_string (must (destruct_string e))
else if is_list e then
lowstarize_list uniq (must (destruct_list e))
else if is_tuple e then
lowstarize_tuple uniq (must (destruct_tuple e))
else
uniq, [], e
and lowstarize_list (uniq: gensym) (es: list term): Tac (gensym * list sigelt * term) =
let uniq, ses, es = fold_left (fun (uniq, ses, es) e ->
let uniq, se, e = lowstarize_expr uniq e in
uniq, List.Tot.rev_acc se ses, e :: es
) (uniq, [], []) es in
let es = List.rev es in
let l = List.length es in
let uniq, se, e = mk_gcmalloc_of_list uniq (mk_list es) l None in
uniq, List.rev (se :: ses), e
and lowstarize_tuple (uniq: gensym) (es: list term): Tac (gensym * list sigelt * term) =
let uniq, ses, es = fold_left (fun (uniq, ses, es) e ->
let uniq, se, e = lowstarize_expr uniq e in
uniq, List.Tot.rev_acc se ses, e :: es
) (uniq, [], []) es in
let es = List.rev es in
if List.Tot.length es <= 8 then
uniq, List.rev ses, mktuple_n es
else fail "Tuples of more than 8 elements are not supported" | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 232,
"start_col": 0,
"start_line": 198
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None
noextract
let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false
noextract
let mktuple_qns =
[ mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn;
mktuple7_qn; mktuple8_qn ]
noextract
let destruct_tuple (e: term): option (list term) =
let hd, args = collect_app_ln e in
match inspect_ln hd with
| Tv_UInst fv _
| Tv_FVar fv ->
if List.Tot.contains (inspect_fv fv) mktuple_qns then
Some (List.Tot.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []
) args)
else
None
| _ ->
None
noextract
let is_tuple (e: term) =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
List.Tot.contains (inspect_fv fv) mktuple_qns
| _ ->
false
noextract
let destruct_hex (e: term) =
let hd, tl = collect_app e in
if term_eq (`h) hd && List.Tot.length tl > 0 then begin
destruct_string (fst (List.Tot.hd tl))
end else
None
noextract
let is_hex e =
is_some (destruct_hex e)
// Main Tactic. This tactic fetches a top-level term and defines another,
// Low*-ized top-level term for it, where:
// - hex-encoded strings are lifted as top-level constant uint8 arrays
// - references to hex-encoded strings are replaced by a pair of the length
// of the corresponding array, and a reference to that array
// - lists are lifted as top-level arrays (using gcmalloc_of_list)
// - strings that are not marked as hex-encoded are lifted to C.String.t
// - tuples are traversed transparently
// - everything else is left as-is
//
// TODO: instead of pairs, use a dependent type that ties together an array and
// its length
let gensym = string * nat
noextract
let fresh (uniq: gensym): Tac (gensym * name) =
(fst uniq, snd uniq + 1), cur_module () @ [ fst uniq ^ string_of_int (snd uniq) ]
noeq
type lbuffer (a:Type0) =
| LB: len:UInt32.t -> b:B.buffer a{B.len b == len /\ B.recallable b} -> lbuffer a
noextract
let mk_gcmalloc_of_list (uniq: gensym) (arg: term) (l:int) (t: option term):
Tac (gensym * sigelt * term)
=
let def: term = pack (Tv_App
(pack (Tv_App (`LowStar.Buffer.gcmalloc_of_list) (`HS.root, Q_Explicit)))
(arg, Q_Explicit)
) in
let uniq, name = fresh uniq in
let fv: fv = pack_fv name in
let t: term = match t with None -> pack Tv_Unknown | Some t -> t in
let lb = pack_lb ({lb_fv = fv;
lb_us = [];
lb_typ = t;
lb_def = def}) in
let se: sigelt = pack_sigelt (Sg_Let false [lb]) in
uniq, se, mk_e_app (`LB) [mk_uint32 l; pack (Tv_FVar fv)]
noextract
let lowstarize_hex (uniq: gensym) (s: string): Tac (gensym * option sigelt * term) =
if String.length s % 2 <> 0
|| not (List.Tot.for_all is_hex_digit (String.list_of_string s)) then
fail ("Invalid hex string: " ^ s)
else
let constants = as_uint8s [] (String.list_of_string s) in
if String.length s = 0 then
let null = pack (Tv_App (`LowStar.Buffer.null) (`UInt8.t, Q_Implicit)) in
uniq, None, mk_e_app (`LB) [mk_uint32 0; null]
else
let l = normalize_term (String.length s / 2) in
let uniq, se, e = mk_gcmalloc_of_list uniq constants l None in
uniq, Some se, e
// Dependency analysis bug: does not go inside quotations (#1496)
module Whatever = C.String
noextract
let lowstarize_string (s: string): Tac term =
`(C.String.of_literal (`@s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "C.String",
"short_module": "Whatever"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | uniq: Test.Lowstarize.gensym -> e: FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
((Test.Lowstarize.gensym * Prims.list FStar.Stubs.Reflection.Types.sigelt) *
FStar.Stubs.Reflection.Types.term) | FStar.Tactics.Effect.Tac | [] | [
"lowstarize_expr",
"lowstarize_list",
"lowstarize_tuple"
] | [
"Test.Lowstarize.gensym",
"FStar.Stubs.Reflection.Types.term",
"FStar.Pervasives.Native.option",
"FStar.Stubs.Reflection.Types.sigelt",
"FStar.Pervasives.Native.Mktuple3",
"Prims.list",
"Prims.Nil",
"Prims.Cons",
"FStar.Pervasives.Native.tuple3",
"Test.Lowstarize.lowstarize_hex",
"Prims.string",
"Test.Lowstarize.must",
"Test.Lowstarize.destruct_hex",
"Prims.bool",
"Test.Lowstarize.is_string",
"Test.Lowstarize.lowstarize_string",
"Test.Lowstarize.destruct_string",
"Test.Lowstarize.lowstarize_list",
"Test.Lowstarize.destruct_list",
"Test.Lowstarize.lowstarize_tuple",
"Test.Lowstarize.destruct_tuple",
"Test.Lowstarize.is_tuple",
"Test.Lowstarize.is_list",
"Test.Lowstarize.is_hex",
"FStar.Tactics.V1.Derived.norm_term",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.delta",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.primops"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec lowstarize_expr (uniq: gensym) (e: term) : Tac (gensym * list sigelt * term) =
| let e = norm_term [delta; zeta; iota; primops] e in
if is_hex e
then
let uniq, se, e = lowstarize_hex uniq (must (destruct_hex e)) in
match se with
| None -> uniq, [], e
| Some se -> uniq, [se], e
else
if is_string e
then uniq, [], lowstarize_string (must (destruct_string e))
else
if is_list e
then lowstarize_list uniq (must (destruct_list e))
else if is_tuple e then lowstarize_tuple uniq (must (destruct_tuple e)) else uniq, [], e | false |
Test.Lowstarize.fst | Test.Lowstarize.lowstarize_tuple | val lowstarize_tuple (uniq: gensym) (es: list term) : Tac (gensym * list sigelt * term) | val lowstarize_tuple (uniq: gensym) (es: list term) : Tac (gensym * list sigelt * term) | let rec lowstarize_expr (uniq: gensym) (e: term): Tac (gensym * list sigelt * term) =
let e = norm_term [ delta; zeta; iota; primops ] e in
if is_hex e then
let uniq, se, e = lowstarize_hex uniq (must (destruct_hex e)) in
match se with
| None -> uniq, [], e
| Some se -> uniq, [se], e
else if is_string e then
uniq, [], lowstarize_string (must (destruct_string e))
else if is_list e then
lowstarize_list uniq (must (destruct_list e))
else if is_tuple e then
lowstarize_tuple uniq (must (destruct_tuple e))
else
uniq, [], e
and lowstarize_list (uniq: gensym) (es: list term): Tac (gensym * list sigelt * term) =
let uniq, ses, es = fold_left (fun (uniq, ses, es) e ->
let uniq, se, e = lowstarize_expr uniq e in
uniq, List.Tot.rev_acc se ses, e :: es
) (uniq, [], []) es in
let es = List.rev es in
let l = List.length es in
let uniq, se, e = mk_gcmalloc_of_list uniq (mk_list es) l None in
uniq, List.rev (se :: ses), e
and lowstarize_tuple (uniq: gensym) (es: list term): Tac (gensym * list sigelt * term) =
let uniq, ses, es = fold_left (fun (uniq, ses, es) e ->
let uniq, se, e = lowstarize_expr uniq e in
uniq, List.Tot.rev_acc se ses, e :: es
) (uniq, [], []) es in
let es = List.rev es in
if List.Tot.length es <= 8 then
uniq, List.rev ses, mktuple_n es
else fail "Tuples of more than 8 elements are not supported" | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 232,
"start_col": 0,
"start_line": 198
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None
noextract
let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false
noextract
let mktuple_qns =
[ mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn;
mktuple7_qn; mktuple8_qn ]
noextract
let destruct_tuple (e: term): option (list term) =
let hd, args = collect_app_ln e in
match inspect_ln hd with
| Tv_UInst fv _
| Tv_FVar fv ->
if List.Tot.contains (inspect_fv fv) mktuple_qns then
Some (List.Tot.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []
) args)
else
None
| _ ->
None
noextract
let is_tuple (e: term) =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
List.Tot.contains (inspect_fv fv) mktuple_qns
| _ ->
false
noextract
let destruct_hex (e: term) =
let hd, tl = collect_app e in
if term_eq (`h) hd && List.Tot.length tl > 0 then begin
destruct_string (fst (List.Tot.hd tl))
end else
None
noextract
let is_hex e =
is_some (destruct_hex e)
// Main Tactic. This tactic fetches a top-level term and defines another,
// Low*-ized top-level term for it, where:
// - hex-encoded strings are lifted as top-level constant uint8 arrays
// - references to hex-encoded strings are replaced by a pair of the length
// of the corresponding array, and a reference to that array
// - lists are lifted as top-level arrays (using gcmalloc_of_list)
// - strings that are not marked as hex-encoded are lifted to C.String.t
// - tuples are traversed transparently
// - everything else is left as-is
//
// TODO: instead of pairs, use a dependent type that ties together an array and
// its length
let gensym = string * nat
noextract
let fresh (uniq: gensym): Tac (gensym * name) =
(fst uniq, snd uniq + 1), cur_module () @ [ fst uniq ^ string_of_int (snd uniq) ]
noeq
type lbuffer (a:Type0) =
| LB: len:UInt32.t -> b:B.buffer a{B.len b == len /\ B.recallable b} -> lbuffer a
noextract
let mk_gcmalloc_of_list (uniq: gensym) (arg: term) (l:int) (t: option term):
Tac (gensym * sigelt * term)
=
let def: term = pack (Tv_App
(pack (Tv_App (`LowStar.Buffer.gcmalloc_of_list) (`HS.root, Q_Explicit)))
(arg, Q_Explicit)
) in
let uniq, name = fresh uniq in
let fv: fv = pack_fv name in
let t: term = match t with None -> pack Tv_Unknown | Some t -> t in
let lb = pack_lb ({lb_fv = fv;
lb_us = [];
lb_typ = t;
lb_def = def}) in
let se: sigelt = pack_sigelt (Sg_Let false [lb]) in
uniq, se, mk_e_app (`LB) [mk_uint32 l; pack (Tv_FVar fv)]
noextract
let lowstarize_hex (uniq: gensym) (s: string): Tac (gensym * option sigelt * term) =
if String.length s % 2 <> 0
|| not (List.Tot.for_all is_hex_digit (String.list_of_string s)) then
fail ("Invalid hex string: " ^ s)
else
let constants = as_uint8s [] (String.list_of_string s) in
if String.length s = 0 then
let null = pack (Tv_App (`LowStar.Buffer.null) (`UInt8.t, Q_Implicit)) in
uniq, None, mk_e_app (`LB) [mk_uint32 0; null]
else
let l = normalize_term (String.length s / 2) in
let uniq, se, e = mk_gcmalloc_of_list uniq constants l None in
uniq, Some se, e
// Dependency analysis bug: does not go inside quotations (#1496)
module Whatever = C.String
noextract
let lowstarize_string (s: string): Tac term =
`(C.String.of_literal (`@s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "C.String",
"short_module": "Whatever"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | uniq: Test.Lowstarize.gensym -> es: Prims.list FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
((Test.Lowstarize.gensym * Prims.list FStar.Stubs.Reflection.Types.sigelt) *
FStar.Stubs.Reflection.Types.term) | FStar.Tactics.Effect.Tac | [] | [
"lowstarize_expr",
"lowstarize_list",
"lowstarize_tuple"
] | [
"Test.Lowstarize.gensym",
"Prims.list",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.Types.sigelt",
"Prims.op_LessThanOrEqual",
"FStar.List.Tot.Base.length",
"FStar.Pervasives.Native.Mktuple3",
"FStar.List.Tot.Base.rev",
"FStar.Reflection.V1.Derived.mktuple_n",
"FStar.Pervasives.Native.tuple3",
"Prims.bool",
"FStar.Tactics.V1.Derived.fail",
"FStar.Tactics.Util.fold_left",
"FStar.List.Tot.Base.rev_acc",
"Prims.Cons",
"Test.Lowstarize.lowstarize_expr",
"Prims.Nil"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec lowstarize_tuple (uniq: gensym) (es: list term) : Tac (gensym * list sigelt * term) =
| let uniq, ses, es =
fold_left (fun (uniq, ses, es) e ->
let uniq, se, e = lowstarize_expr uniq e in
uniq, List.Tot.rev_acc se ses, e :: es)
(uniq, [], [])
es
in
let es = List.rev es in
if List.Tot.length es <= 8
then uniq, List.rev ses, mktuple_n es
else fail "Tuples of more than 8 elements are not supported" | false |
Test.Lowstarize.fst | Test.Lowstarize.lowstarize_list | val lowstarize_list (uniq: gensym) (es: list term) : Tac (gensym * list sigelt * term) | val lowstarize_list (uniq: gensym) (es: list term) : Tac (gensym * list sigelt * term) | let rec lowstarize_expr (uniq: gensym) (e: term): Tac (gensym * list sigelt * term) =
let e = norm_term [ delta; zeta; iota; primops ] e in
if is_hex e then
let uniq, se, e = lowstarize_hex uniq (must (destruct_hex e)) in
match se with
| None -> uniq, [], e
| Some se -> uniq, [se], e
else if is_string e then
uniq, [], lowstarize_string (must (destruct_string e))
else if is_list e then
lowstarize_list uniq (must (destruct_list e))
else if is_tuple e then
lowstarize_tuple uniq (must (destruct_tuple e))
else
uniq, [], e
and lowstarize_list (uniq: gensym) (es: list term): Tac (gensym * list sigelt * term) =
let uniq, ses, es = fold_left (fun (uniq, ses, es) e ->
let uniq, se, e = lowstarize_expr uniq e in
uniq, List.Tot.rev_acc se ses, e :: es
) (uniq, [], []) es in
let es = List.rev es in
let l = List.length es in
let uniq, se, e = mk_gcmalloc_of_list uniq (mk_list es) l None in
uniq, List.rev (se :: ses), e
and lowstarize_tuple (uniq: gensym) (es: list term): Tac (gensym * list sigelt * term) =
let uniq, ses, es = fold_left (fun (uniq, ses, es) e ->
let uniq, se, e = lowstarize_expr uniq e in
uniq, List.Tot.rev_acc se ses, e :: es
) (uniq, [], []) es in
let es = List.rev es in
if List.Tot.length es <= 8 then
uniq, List.rev ses, mktuple_n es
else fail "Tuples of more than 8 elements are not supported" | {
"file_name": "providers/test/Test.Lowstarize.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 62,
"end_line": 232,
"start_col": 0,
"start_line": 198
} | module Test.Lowstarize
open FStar.List.Tot
open FStar.Tactics
open LowStar.BufferOps
open Lib.Meta
module B = LowStar.Buffer
module HS = FStar.HyperStack
// We rely on a single user-level function: h, which indicates that the string
// is hex-encoded. Otherwise, the string becomes a call to C.String.of_literal.
assume new type hex_encoded
assume val h: string -> hex_encoded
noextract
let mk_int (i: int): term =
pack_ln (Tv_Const (C_Int i))
noextract
let mk_uint8 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt8";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let mk_uint32 (x: int): Tac term =
pack (Tv_App (pack (Tv_FVar (pack_fv ["FStar";"UInt32";"__uint_to_t"])))
(mk_int x, Q_Explicit))
noextract
let rec as_uint8s acc
(cs:list Char.char{normalize (List.Tot.length cs % 2 = 0) /\
normalize (List.Tot.for_all is_hex_digit cs)}):
Tac term (decreases cs)
=
match cs with
| c1 :: c2 :: cs ->
as_uint8s (mk_uint8 (byte_of_hex c1 c2) :: acc) cs
| [] ->
mk_list (List.rev acc)
noextract
let destruct_string e =
match inspect_ln e with
| Tv_Const (C_String s) -> Some s
| _ -> None
noextract
let is_some = function Some _ -> true | None -> false
noextract
let is_string e =
is_some (destruct_string e)
noextract
let must (x: option 'a): Tac 'a =
match x with
| Some x -> x
| None -> fail "must"
noextract
let rec destruct_list (e: term): Tac (option (list term)) =
let hd, args = collect_app e in
match inspect_ln hd, args with
| Tv_UInst fv _, [ _; hd, _; tl, _ ]
| Tv_FVar fv, [ _; hd, _; tl, _ ] ->
if inspect_fv fv = cons_qn then
Some (hd :: must (destruct_list tl))
else
None
| Tv_UInst fv _, _
| Tv_FVar fv, _ ->
if inspect_fv fv = nil_qn then
Some []
else
None
| _ ->
None
noextract
let is_list e =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
inspect_fv fv = nil_qn || inspect_fv fv = cons_qn
| _ ->
false
noextract
let mktuple_qns =
[ mktuple2_qn; mktuple3_qn; mktuple4_qn; mktuple5_qn; mktuple6_qn;
mktuple7_qn; mktuple8_qn ]
noextract
let destruct_tuple (e: term): option (list term) =
let hd, args = collect_app_ln e in
match inspect_ln hd with
| Tv_UInst fv _
| Tv_FVar fv ->
if List.Tot.contains (inspect_fv fv) mktuple_qns then
Some (List.Tot.concatMap (fun (t, q) ->
match q with
| Q_Explicit -> [t]
| _ -> []
) args)
else
None
| _ ->
None
noextract
let is_tuple (e: term) =
match inspect (fst (collect_app e)) with
| Tv_UInst fv _
| Tv_FVar fv ->
List.Tot.contains (inspect_fv fv) mktuple_qns
| _ ->
false
noextract
let destruct_hex (e: term) =
let hd, tl = collect_app e in
if term_eq (`h) hd && List.Tot.length tl > 0 then begin
destruct_string (fst (List.Tot.hd tl))
end else
None
noextract
let is_hex e =
is_some (destruct_hex e)
// Main Tactic. This tactic fetches a top-level term and defines another,
// Low*-ized top-level term for it, where:
// - hex-encoded strings are lifted as top-level constant uint8 arrays
// - references to hex-encoded strings are replaced by a pair of the length
// of the corresponding array, and a reference to that array
// - lists are lifted as top-level arrays (using gcmalloc_of_list)
// - strings that are not marked as hex-encoded are lifted to C.String.t
// - tuples are traversed transparently
// - everything else is left as-is
//
// TODO: instead of pairs, use a dependent type that ties together an array and
// its length
let gensym = string * nat
noextract
let fresh (uniq: gensym): Tac (gensym * name) =
(fst uniq, snd uniq + 1), cur_module () @ [ fst uniq ^ string_of_int (snd uniq) ]
noeq
type lbuffer (a:Type0) =
| LB: len:UInt32.t -> b:B.buffer a{B.len b == len /\ B.recallable b} -> lbuffer a
noextract
let mk_gcmalloc_of_list (uniq: gensym) (arg: term) (l:int) (t: option term):
Tac (gensym * sigelt * term)
=
let def: term = pack (Tv_App
(pack (Tv_App (`LowStar.Buffer.gcmalloc_of_list) (`HS.root, Q_Explicit)))
(arg, Q_Explicit)
) in
let uniq, name = fresh uniq in
let fv: fv = pack_fv name in
let t: term = match t with None -> pack Tv_Unknown | Some t -> t in
let lb = pack_lb ({lb_fv = fv;
lb_us = [];
lb_typ = t;
lb_def = def}) in
let se: sigelt = pack_sigelt (Sg_Let false [lb]) in
uniq, se, mk_e_app (`LB) [mk_uint32 l; pack (Tv_FVar fv)]
noextract
let lowstarize_hex (uniq: gensym) (s: string): Tac (gensym * option sigelt * term) =
if String.length s % 2 <> 0
|| not (List.Tot.for_all is_hex_digit (String.list_of_string s)) then
fail ("Invalid hex string: " ^ s)
else
let constants = as_uint8s [] (String.list_of_string s) in
if String.length s = 0 then
let null = pack (Tv_App (`LowStar.Buffer.null) (`UInt8.t, Q_Implicit)) in
uniq, None, mk_e_app (`LB) [mk_uint32 0; null]
else
let l = normalize_term (String.length s / 2) in
let uniq, se, e = mk_gcmalloc_of_list uniq constants l None in
uniq, Some se, e
// Dependency analysis bug: does not go inside quotations (#1496)
module Whatever = C.String
noextract
let lowstarize_string (s: string): Tac term =
`(C.String.of_literal (`@s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.Meta.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Tactics.fst.checked",
"FStar.String.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.List.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Char.fsti.checked",
"C.String.fsti.checked"
],
"interface_file": false,
"source_file": "Test.Lowstarize.fst"
} | [
{
"abbrev": true,
"full_module": "C.String",
"short_module": "Whatever"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "Lib.Meta",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "Test",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | uniq: Test.Lowstarize.gensym -> es: Prims.list FStar.Stubs.Reflection.Types.term
-> FStar.Tactics.Effect.Tac
((Test.Lowstarize.gensym * Prims.list FStar.Stubs.Reflection.Types.sigelt) *
FStar.Stubs.Reflection.Types.term) | FStar.Tactics.Effect.Tac | [] | [
"lowstarize_expr",
"lowstarize_list",
"lowstarize_tuple"
] | [
"Test.Lowstarize.gensym",
"Prims.list",
"FStar.Stubs.Reflection.Types.term",
"FStar.Stubs.Reflection.Types.sigelt",
"FStar.Pervasives.Native.Mktuple3",
"FStar.List.Tot.Base.rev",
"Prims.Cons",
"FStar.Pervasives.Native.tuple3",
"Test.Lowstarize.mk_gcmalloc_of_list",
"FStar.Reflection.V1.Derived.mk_list",
"FStar.Pervasives.Native.None",
"Prims.nat",
"FStar.List.Tot.Base.length",
"FStar.Tactics.Util.fold_left",
"FStar.List.Tot.Base.rev_acc",
"Test.Lowstarize.lowstarize_expr",
"Prims.Nil"
] | [
"mutual recursion"
] | false | true | false | false | false | let rec lowstarize_list (uniq: gensym) (es: list term) : Tac (gensym * list sigelt * term) =
| let uniq, ses, es =
fold_left (fun (uniq, ses, es) e ->
let uniq, se, e = lowstarize_expr uniq e in
uniq, List.Tot.rev_acc se ses, e :: es)
(uniq, [], [])
es
in
let es = List.rev es in
let l = List.length es in
let uniq, se, e = mk_gcmalloc_of_list uniq (mk_list es) l None in
uniq, List.rev (se :: ses), e | false |
Hacl.Impl.SHA2.Generic.fst | Hacl.Impl.SHA2.Generic.finish | val finish: #a:sha2_alg -> #m:m_spec{is_supported a m} -> finish_vec_t a m | val finish: #a:sha2_alg -> #m:m_spec{is_supported a m} -> finish_vec_t a m | let finish #a #m st h =
let h0 = ST.get() in
push_frame();
let hbuf = create (size (lanes a m) *. 8ul *. HD.word_len a) (u8 0) in
let h1 = ST.get() in
store_state st hbuf;
emit hbuf h;
let h2 = ST.get() in
assert (modifies (loc_multi h |+| loc st |+| loc hbuf) h1 h2);
assert (as_seq_multi h2 h == SpecVec.finish #a #m (as_seq h0 st));
pop_frame();
let h3 = ST.get() in
assert (modifies (loc_multi h |+| loc st) h0 h3);
NTup.eq_intro (as_seq_multi h2 h) (as_seq_multi h3 h);
assert (as_seq_multi h2 h == as_seq_multi h3 h);
assert (as_seq_multi h3 h == SpecVec.finish #a #m (as_seq h0 st)) | {
"file_name": "code/sha2-mb/Hacl.Impl.SHA2.Generic.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 67,
"end_line": 366,
"start_col": 0,
"start_line": 351
} | module Hacl.Impl.SHA2.Generic
open FStar.Mul
open FStar.HyperStack
open FStar.HyperStack.All
open Lib.IntTypes
open Lib.NTuple
open Lib.Buffer
open Lib.IntVector
open Lib.MultiBuffer
open Spec.Hash.Definitions
//open Hacl.Hash.Definitions
open Hacl.Spec.SHA2.Vec
open Hacl.Impl.SHA2.Core
module ST = FStar.HyperStack.ST
module NTup = Lib.NTuple
module Constants = Spec.SHA2.Constants
module Spec = Hacl.Spec.SHA2
module SpecVec = Hacl.Spec.SHA2.Vec
module VecTranspose = Lib.IntVector.Transpose
module LSeq = Lib.Sequence
module HD = Hacl.Hash.Definitions
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 50"
(** Top-level constant arrays for the SHA2 algorithms. *)
let h224 : x:glbuffer uint32 8ul{witnessed x Constants.h224 /\ recallable x} =
createL_global Constants.h224_l
let h256 : x:glbuffer uint32 8ul{witnessed x Constants.h256 /\ recallable x} =
createL_global Constants.h256_l
let h384 : x:glbuffer uint64 8ul{witnessed x Constants.h384 /\ recallable x} =
createL_global Constants.h384_l
let h512 : x:glbuffer uint64 8ul{witnessed x Constants.h512 /\ recallable x} =
createL_global Constants.h512_l
noextract inline_for_extraction
let index_h0 (a:sha2_alg) (i:size_t) : Stack (word a)
(requires (fun _ -> size_v i < 8))
(ensures (fun h0 r h1 ->
h0 == h1 /\
r == Seq.index (Spec.h0 a) (size_v i))) =
match a with
| SHA2_224 -> recall h224; recall_contents h224 Constants.h224; h224.(i)
| SHA2_256 -> recall h256; recall_contents h256 Constants.h256; h256.(i)
| SHA2_384 -> recall h384; recall_contents h384 Constants.h384; h384.(i)
| SHA2_512 -> recall h512; recall_contents h512 Constants.h512; h512.(i)
let k224_256 : x:glbuffer uint32 64ul{witnessed x Constants.k224_256 /\ recallable x} =
createL_global Constants.k224_256_l
let k384_512 : x:glbuffer uint64 80ul{witnessed x Constants.k384_512 /\ recallable x} =
createL_global Constants.k384_512_l
noextract inline_for_extraction
let index_k0 (a:sha2_alg) (i:size_t) : Stack (word a)
(requires (fun _ -> size_v i < Spec.size_k_w a))
(ensures (fun h0 r h1 ->
h0 == h1 /\
r == Seq.index (Spec.k0 a) (size_v i))) =
match a with
| SHA2_224 | SHA2_256 ->
recall_contents k224_256 Constants.k224_256;
k224_256.(i)
| SHA2_384 | SHA2_512 ->
recall_contents k384_512 Constants.k384_512;
k384_512.(i)
inline_for_extraction noextract
val shuffle_core: #a:sha2_alg -> #m:m_spec
-> k_t:word a
-> ws_t:element_t a m
-> st:state_t a m ->
Stack unit
(requires fun h -> live h st)
(ensures fun h0 _ h1 ->
modifies (loc st) h0 h1 /\
as_seq h1 st == SpecVec.shuffle_core_spec k_t ws_t (as_seq h0 st))
let shuffle_core #a #m k_t ws_t st =
let hp0 = ST.get() in
let a0 = st.(0ul) in
let b0 = st.(1ul) in
let c0 = st.(2ul) in
let d0 = st.(3ul) in
let e0 = st.(4ul) in
let f0 = st.(5ul) in
let g0 = st.(6ul) in
let h0 = st.(7ul) in
let k_e_t = load_element a m k_t in
let t1 = h0 +| (_Sigma1 e0) +| (_Ch e0 f0 g0) +| k_e_t +| ws_t in
let t2 = (_Sigma0 a0) +| (_Maj a0 b0 c0) in
let a1 = t1 +| t2 in
let b1 = a0 in
let c1 = b0 in
let d1 = c0 in
let e1 = d0 +| t1 in
let f1 = e0 in
let g1 = f0 in
let h1 = g0 in
create8 st a1 b1 c1 d1 e1 f1 g1 h1
#push-options "--z3rlimit 300"
inline_for_extraction noextract
val ws_next: #a:sha2_alg -> #m:m_spec -> ws:ws_t a m ->
Stack unit
(requires fun h -> live h ws)
(ensures fun h0 _ h1 -> modifies (loc ws) h0 h1 /\
as_seq h1 ws == SpecVec.ws_next (as_seq h0 ws))
let ws_next #a #m ws =
let h0 = ST.get() in
loop1 h0 16ul ws
(fun h -> ws_next_inner #a #m)
(fun i ->
Lib.LoopCombinators.unfold_repeati 16 (ws_next_inner #a #m) (as_seq h0 ws) (v i);
let t16 = ws.(i) in
let t15 = ws.((i+.1ul) %. 16ul) in
let t7 = ws.((i+.9ul) %. 16ul) in
let t2 = ws.((i+.14ul) %. 16ul) in
let s1 = _sigma1 t2 in
let s0 = _sigma0 t15 in
ws.(i) <- (s1 +| t7 +| s0 +| t16))
#pop-options
inline_for_extraction noextract
val shuffle: #a:sha2_alg -> #m:m_spec -> ws:ws_t a m -> hash:state_t a m ->
Stack unit
(requires fun h -> live h hash /\ live h ws /\ disjoint hash ws)
(ensures fun h0 _ h1 -> modifies2 ws hash h0 h1 /\
as_seq h1 hash == SpecVec.shuffle #a #m (as_seq h0 ws) (as_seq h0 hash))
let shuffle #a #m ws hash =
let h0 = ST.get() in
loop2 h0 (num_rounds16 a) ws hash
(fun h -> shuffle_inner_loop #a #m)
(fun i ->
Lib.LoopCombinators.unfold_repeati (v (num_rounds16 a)) (shuffle_inner_loop #a #m) (as_seq h0 ws, as_seq h0 hash) (v i);
let h1 = ST.get() in
loop1 h1 16ul hash
(fun h -> shuffle_inner #a #m (as_seq h1 ws) (v i))
(fun j ->
Lib.LoopCombinators.unfold_repeati 16 (shuffle_inner #a #m (as_seq h1 ws) (v i)) (as_seq h1 hash) (v j);
let k_t = index_k0 a (16ul *. i +. j) in
let ws_t = ws.(j) in
shuffle_core k_t ws_t hash);
if i <. num_rounds16 a -. 1ul then ws_next ws)
inline_for_extraction noextract
val alloc: a:sha2_alg -> m:m_spec ->
StackInline (state_t a m)
(requires fun h -> True)
(ensures fun h0 b h1 -> live h1 b /\ stack_allocated b h0 h1 (Seq.create 8 (zero_element a m)))
let alloc a m = Lib.Buffer.create 8ul (zero_element a m)
inline_for_extraction noextract
let init_vec_t (a:sha2_alg) (m:m_spec) = hash:state_t a m ->
Stack unit
(requires fun h -> live h hash)
(ensures fun h0 _ h1 -> modifies1 hash h0 h1 /\
as_seq h1 hash == SpecVec.init a m)
inline_for_extraction noextract
val init: #a:sha2_alg -> #m:m_spec -> init_vec_t a m
let init #a #m hash =
let h0 = ST.get() in
fill h0 8ul hash
(fun h i -> load_element a m (Seq.index (Spec.h0 a) i))
(fun i ->
let hi = index_h0 a i in
load_element a m hi);
let h1 = ST.get() in
LSeq.eq_intro (as_seq h1 hash) (LSeq.createi 8 (fun i -> load_element a m (Seq.index (Spec.h0 a) i)))
inline_for_extraction noextract
let update_vec_t (a:sha2_alg) (m:m_spec{is_supported a m}) =
b:multibuf (lanes a m) (HD.block_len a)
-> hash:state_t a m ->
Stack unit
(requires fun h -> live_multi h b /\ live h hash)
(ensures fun h0 _ h1 -> modifies (loc hash) h0 h1 /\
as_seq h1 hash == SpecVec.update (as_seq_multi h0 b) (as_seq h0 hash))
#push-options "--z3rlimit 200"
inline_for_extraction noextract
val update: #a:sha2_alg -> #m:m_spec{is_supported a m} -> update_vec_t a m
let update #a #m b hash =
let h0 = ST.get() in
push_frame ();
let h1 = ST.get() in
let hash_old = create 8ul (zero_element a m) in
let ws = create 16ul (zero_element a m) in
assert (disjoint_multi b hash_old);
assert (disjoint_multi b ws);
assert (disjoint ws hash_old);
assert (disjoint hash hash_old);
assert (disjoint ws hash);
copy hash_old hash;
let h2 = ST.get() in
assert (live_multi h2 b);
NTup.(eq_intro (as_seq_multi h2 b) (as_seq_multi h0 b));
load_ws b ws;
let h3 = ST.get() in
assert (modifies (loc ws |+| loc hash_old) h0 h3);
assert (as_seq h3 ws == SpecVec.load_ws (as_seq_multi h2 b));
shuffle ws hash;
let h4 = ST.get() in
assert (modifies (loc hash |+| (loc ws |+| loc hash_old)) h0 h4);
assert (as_seq h4 hash == SpecVec.shuffle (as_seq h3 ws) (as_seq h0 hash));
map2T 8ul hash (+|) hash hash_old;
let h5 = ST.get() in
assert (modifies (loc hash |+| (loc ws |+| loc hash_old)) h0 h5);
reveal_opaque (`%SpecVec.update) (SpecVec.update #a #m);
assert (as_seq h5 hash == SpecVec.update (as_seq_multi h0 b) (as_seq h0 hash));
pop_frame()
#pop-options
inline_for_extraction noextract
let update_last_vec_t' (a:sha2_alg) (m:m_spec{is_supported a m}) =
totlen:len_t a
-> len:size_t{v len <= block_length a}
-> b:multibuf (lanes a m) len
-> hash:state_t a m ->
Stack unit
(requires fun h -> live_multi h b /\ live h hash /\ disjoint_multi b hash)
(ensures fun h0 _ h1 -> modifies (loc hash) h0 h1 /\
as_seq h1 hash == SpecVec.update_last totlen (v len) (as_seq_multi h0 b) (as_seq h0 hash))
inline_for_extraction noextract
let update_last_vec_t (a:sha2_alg) (m:m_spec{is_supported a m}) =
upd:update_vec_t a m -> update_last_vec_t' a m
#push-options "--z3rlimit 350"
inline_for_extraction noextract
val update_last: #a:sha2_alg -> #m:m_spec{is_supported a m} -> update_last_vec_t a m
let update_last #a #m upd totlen len b hash =
let h0 = ST.get() in
push_frame ();
let h1 = ST.get() in
let blocks = padded_blocks a len in
let fin = blocks *! HD.block_len a in
let last = create (size (lanes a m) *! 2ul *! HD.block_len a) (u8 0) in
let totlen_buf = create (len_len a) (u8 0) in
let total_len_bits = secret (shift_left #(len_int_type a) totlen 3ul) in
Lib.ByteBuffer.uint_to_bytes_be #(len_int_type a) totlen_buf total_len_bits;
let h2 = ST.get () in
NTup.eq_intro (as_seq_multi h2 b) (as_seq_multi h0 b);
assert (as_seq h2 totlen_buf ==
Lib.ByteSequence.uint_to_bytes_be #(len_int_type a) total_len_bits);
let (last0,last1) = load_last #a #m totlen_buf len b fin last in
let h3 = ST.get () in
assert ((as_seq_multi h3 last0, as_seq_multi h3 last1) ==
SpecVec.load_last #a #m (as_seq h2 totlen_buf) (v fin) (v len) (as_seq_multi h2 b));
assert (disjoint_multi last1 hash);
upd last0 hash;
let h4 = ST.get() in
assert (modifies (loc hash |+| loc last |+| loc totlen_buf) h1 h3);
assert (as_seq h4 hash == SpecVec.update (as_seq_multi h3 last0) (as_seq h3 hash));
NTup.eq_intro (as_seq_multi h4 last1) (as_seq_multi h3 last1);
assert (v blocks > 1 ==> blocks >. 1ul);
assert (blocks >. 1ul ==> v blocks > 1);
assert (not (blocks >. 1ul) ==> not (v blocks > 1));
if blocks >. 1ul then (
upd last1 hash;
let h5 = ST.get() in
assert (as_seq h5 hash == SpecVec.update (as_seq_multi h4 last1) (as_seq h4 hash));
assert (modifies (loc hash |+| loc last |+| loc totlen_buf) h1 h5);
assert (as_seq h5 hash == SpecVec.update_last totlen (v len) (as_seq_multi h0 b) (as_seq h0 hash));
pop_frame()
) else (
let h6 = ST.get() in
assert (h4 == h6);
assert (modifies (loc hash |+| loc totlen_buf |+| loc last) h1 h6);
assert (as_seq h6 hash == SpecVec.update_last totlen (v len) (as_seq_multi h0 b) (as_seq h0 hash));
pop_frame())
#pop-options
// The type of update_nblocks_vec_t applied to a specific update function
inline_for_extraction noextract
let update_nblocks_vec_t' (a:sha2_alg) (m:Hacl.Spec.SHA2.Vec.(m:m_spec{is_supported a m})) =
let open Lib.IntTypes in
let open Lib.MultiBuffer in
let open Lib.Buffer in
let open Hacl.Spec.SHA2.Vec in
let open Hacl.Impl.SHA2.Core in
len:size_t
-> b:multibuf (lanes a m) len
-> st:state_t a m ->
Stack unit
(requires fun h0 -> live_multi h0 b /\ live h0 st /\ disjoint_multi b st)
(ensures fun h0 _ h1 -> modifies (loc st) h0 h1 /\
(lemma_len_lt_max_a_fits_size_t a len;
as_seq h1 st == update_nblocks #a #m (v len) (as_seq_multi h0 b) (as_seq h0 st)))
inline_for_extraction noextract
let update_nblocks_vec_t (a:sha2_alg) (m:m_spec{is_supported a m}) =
upd:update_vec_t a m -> update_nblocks_vec_t' a m
#push-options "--z3rlimit 200"
inline_for_extraction noextract
val update_nblocks: #a:sha2_alg -> #m:m_spec{is_supported a m} -> update_nblocks_vec_t a m
let update_nblocks #a #m upd len b st =
lemma_len_lt_max_a_fits_size_t a len;
let blocks = len /. HD.block_len a in
let h0 = ST.get() in
loop1 h0 blocks st
(fun h -> SpecVec.update_block #a #m (v len) (as_seq_multi h0 b))
(fun i ->
Lib.LoopCombinators.unfold_repeati (v blocks) (SpecVec.update_block #a #m (v len) (as_seq_multi h0 b)) (as_seq h0 st) (v i);
let h0' = ST.get() in
let mb = get_multiblock len b i in
upd mb st;
let h1 = ST.get() in
assert (modifies (loc st) h0 h1);
NTup.eq_intro (as_seq_multi h0' b) (as_seq_multi h0 b);
assert (as_seq h1 st == SpecVec.update_block #a #m (v len) (as_seq_multi h0 b) (v i) (as_seq h0' st)))
#pop-options
inline_for_extraction noextract
let finish_vec_t (a:sha2_alg) (m:m_spec{is_supported a m}) =
st:state_t a m
-> h:multibuf (lanes a m) (HD.hash_len a) ->
Stack unit
(requires fun h0 -> live_multi h0 h /\ internally_disjoint h /\ live h0 st /\ disjoint_multi h st)
(ensures fun h0 _ h1 -> modifies (loc_multi h |+| loc st) h0 h1 /\
as_seq_multi h1 h == SpecVec.finish #a #m (as_seq h0 st))
#push-options "--z3rlimit 100"
inline_for_extraction noextract | {
"checked_file": "/",
"dependencies": [
"Spec.SHA2.Constants.fst.checked",
"Spec.Hash.Definitions.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.NTuple.fsti.checked",
"Lib.MultiBuffer.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntVector.Transpose.fsti.checked",
"Lib.IntVector.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.SHA2.Vec.fst.checked",
"Hacl.Spec.SHA2.fst.checked",
"Hacl.Impl.SHA2.Core.fst.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Impl.SHA2.Generic.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "HD"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "Lib.IntVector.Transpose",
"short_module": "VecTranspose"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": "SpecVec"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.SHA2",
"short_module": "Spec"
},
{
"abbrev": true,
"full_module": "Spec.SHA2.Constants",
"short_module": "Constants"
},
{
"abbrev": true,
"full_module": "Lib.NTuple",
"short_module": "NTup"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.SHA2.Vec",
"short_module": null
},
{
"abbrev": false,
"full_module": "Spec.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.MultiBuffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntVector",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Buffer",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.NTuple",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.SHA2",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Hacl.Impl.SHA2.Generic.finish_vec_t a m | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.sha2_alg",
"Hacl.Spec.SHA2.Vec.m_spec",
"Hacl.Spec.SHA2.Vec.is_supported",
"Hacl.Impl.SHA2.Core.state_t",
"Lib.MultiBuffer.multibuf",
"Hacl.Spec.SHA2.Vec.lanes",
"Hacl.Hash.Definitions.hash_len",
"Prims._assert",
"Prims.eq2",
"Lib.NTuple.ntuple",
"FStar.Seq.Properties.lseq",
"Lib.IntTypes.uint8",
"Spec.Hash.Definitions.hash_length",
"Lib.MultiBuffer.as_seq_multi",
"Hacl.Spec.SHA2.Vec.finish",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Spec.SHA2.Vec.element_t",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Lib.MultiBuffer.multiseq",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.NTuple.eq_intro",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.MultiBuffer.loc_multi",
"Lib.Buffer.loc",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.HyperStack.ST.pop_frame",
"Hacl.Impl.SHA2.Core.emit",
"Hacl.Impl.SHA2.Core.store_state",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.IntTypes.mul_mod",
"Lib.IntTypes.mk_int",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Hacl.Hash.Definitions.word_len",
"Lib.Buffer.create",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.size",
"Lib.IntTypes.u8",
"Lib.Buffer.lbuffer",
"FStar.HyperStack.ST.push_frame"
] | [] | false | false | false | false | false | let finish #a #m st h =
| let h0 = ST.get () in
push_frame ();
let hbuf = create (size (lanes a m) *. 8ul *. HD.word_len a) (u8 0) in
let h1 = ST.get () in
store_state st hbuf;
emit hbuf h;
let h2 = ST.get () in
assert (modifies (loc_multi h |+| loc st |+| loc hbuf) h1 h2);
assert (as_seq_multi h2 h == SpecVec.finish #a #m (as_seq h0 st));
pop_frame ();
let h3 = ST.get () in
assert (modifies (loc_multi h |+| loc st) h0 h3);
NTup.eq_intro (as_seq_multi h2 h) (as_seq_multi h3 h);
assert (as_seq_multi h2 h == as_seq_multi h3 h);
assert (as_seq_multi h3 h == SpecVec.finish #a #m (as_seq h0 st)) | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_mul_open | val bn_karatsuba_mul_open: #t:limb_t -> (self: unit -> bn_karatsuba_mul_st t) -> bn_karatsuba_mul_st t | val bn_karatsuba_mul_open: #t:limb_t -> (self: unit -> bn_karatsuba_mul_st t) -> bn_karatsuba_mul_st t | let bn_karatsuba_mul_open #t (self: unit -> bn_karatsuba_mul_st t) len a b tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_mul_]]
(K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_mul_u len a len b res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let b0 = sub b 0ul len2 in
let b1 = sub b len2 len2 in
// tmp = [ t0_len2; t1_len2; ..]
let t0 = sub tmp 0ul len2 in
let t1 = sub tmp len2 len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
let c1 = bn_sign_abs b0 b1 tmp' t1 in
// tmp = [ t0_len2; t1_len2; t23_len; ..]
(**) let h0 = ST.get () in
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 t1 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 b0 tmp1 r01;
self () len2 a1 b1 tmp1 r23;
let c = bn_karatsuba_last len c0 c1 tmp res in
LowStar.Ignore.ignore c;
() end | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 249,
"start_col": 0,
"start_line": 214
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
#push-options "--z3rlimit 150"
(* from Jonathan:
let karatsuba_t = dst:bignum -> a:bignum -> b:bignum -> Stack unit ensures dst = a * b
inline_for_extraction
let karatsuba_open (self: unit -> karastuba_t): fun dst a b ->
... self () dst' a' b' ...
let rec karatsuba () = karatsuba_open karastuba
*)
inline_for_extraction noextract
let bn_karatsuba_mul_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t}
-> a:lbignum t len
-> b:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b))
inline_for_extraction noextract | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | self: (self: Prims.unit -> Hacl.Bignum.Karatsuba.bn_karatsuba_mul_st t)
-> Hacl.Bignum.Karatsuba.bn_karatsuba_mul_st t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Prims.unit",
"Hacl.Bignum.Karatsuba.bn_karatsuba_mul_st",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Plus_Bang",
"Prims.op_BarBar",
"Lib.IntTypes.op_Less_Dot",
"Hacl.Bignum.Karatsuba.bn_mul_threshold",
"Lib.IntTypes.op_Equals_Dot",
"Lib.IntTypes.op_Percent_Dot",
"Hacl.Bignum.Multiplication.bn_mul_u",
"Prims.bool",
"LowStar.Ignore.ignore",
"Hacl.Bignum.Definitions.limb",
"Hacl.Bignum.Karatsuba.bn_karatsuba_last",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.Buffer.sub",
"Lib.IntTypes.add",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Bignum.Karatsuba.bn_sign_abs",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Slash_Dot",
"FStar.Pervasives.norm_spec",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.primops",
"FStar.Pervasives.delta_only",
"Prims.string",
"Prims.Nil",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.op_Addition",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_mul_"
] | [] | false | false | false | false | false | let bn_karatsuba_mul_open #t (self: (unit -> bn_karatsuba_mul_st t)) len a b tmp res =
| let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_mul_]]
(K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b));
if len <. bn_mul_threshold || len %. 2ul =. 1ul
then bn_mul_u len a len b res
else
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let b0 = sub b 0ul len2 in
let b1 = sub b len2 len2 in
let t0 = sub tmp 0ul len2 in
let t1 = sub tmp len2 len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
let c1 = bn_sign_abs b0 b1 tmp' t1 in
let h0 = ST.get () in
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 t1 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 b0 tmp1 r01;
self () len2 a1 b1 tmp1 r23;
let c = bn_karatsuba_last len c0 c1 tmp res in
LowStar.Ignore.ignore c;
() | false |
Hacl.K256.Field.fsti | Hacl.K256.Field.nlimb | val nlimb : FStar.UInt32.t | let nlimb = 5ul | {
"file_name": "code/k256/Hacl.K256.Field.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 15,
"end_line": 23,
"start_col": 0,
"start_line": 23
} | module Hacl.K256.Field
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 BSeq = Lib.ByteSequence
module S = Spec.K256
include Hacl.Spec.K256.Field52.Definitions
module BI = Hacl.Spec.K256.Field52
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** Specialized bignum library with a radix-2^{52} *) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Spec.K256.Field52.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.K256.Field.fsti"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52",
"short_module": "BI"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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"
} | false | FStar.UInt32.t | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.__uint_to_t"
] | [] | false | false | false | true | false | let nlimb =
| 5ul | false |
|
Hacl.K256.Field.fsti | Hacl.K256.Field.felem | val felem : Type0 | let felem = lbuffer uint64 nlimb | {
"file_name": "code/k256/Hacl.K256.Field.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 26,
"start_col": 0,
"start_line": 26
} | module Hacl.K256.Field
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 BSeq = Lib.ByteSequence
module S = Spec.K256
include Hacl.Spec.K256.Field52.Definitions
module BI = Hacl.Spec.K256.Field52
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** Specialized bignum library with a radix-2^{52} *)
inline_for_extraction noextract
let nlimb = 5ul | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Spec.K256.Field52.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.K256.Field.fsti"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52",
"short_module": "BI"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint64",
"Hacl.K256.Field.nlimb"
] | [] | false | false | false | true | true | let felem =
| lbuffer uint64 nlimb | false |
|
Hacl.K256.Field.fsti | Hacl.K256.Field.as_nat | val as_nat (h: mem) (e: felem) : GTot nat | val as_nat (h: mem) (e: felem) : GTot nat | let as_nat (h:mem) (e:felem) : GTot nat =
as_nat5 (as_felem5 h e) | {
"file_name": "code/k256/Hacl.K256.Field.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 36,
"start_col": 0,
"start_line": 35
} | module Hacl.K256.Field
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 BSeq = Lib.ByteSequence
module S = Spec.K256
include Hacl.Spec.K256.Field52.Definitions
module BI = Hacl.Spec.K256.Field52
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** Specialized bignum library with a radix-2^{52} *)
inline_for_extraction noextract
let nlimb = 5ul
inline_for_extraction noextract
let felem = lbuffer uint64 nlimb
noextract
let as_felem5 (h:mem) (e:felem) : GTot felem5 =
let open Lib.Sequence in
let s = as_seq h e in
(s.[0], s.[1], s.[2], s.[3], s.[4]) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Spec.K256.Field52.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.K256.Field.fsti"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52",
"short_module": "BI"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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"
} | false | h: FStar.Monotonic.HyperStack.mem -> e: Hacl.K256.Field.felem -> Prims.GTot Prims.nat | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Hacl.K256.Field.felem",
"Hacl.Spec.K256.Field52.Definitions.as_nat5",
"Hacl.K256.Field.as_felem5",
"Prims.nat"
] | [] | false | false | false | false | false | let as_nat (h: mem) (e: felem) : GTot nat =
| as_nat5 (as_felem5 h e) | false |
Hacl.K256.Field.fsti | Hacl.K256.Field.inv_fully_reduced5 | val inv_fully_reduced5 : f: Hacl.Spec.K256.Field52.Definitions.felem5 -> Prims.logical | let inv_fully_reduced5 (f:felem5) =
felem_fits5 f (1,1,1,1,1) /\
as_nat5 f < S.prime | {
"file_name": "code/k256/Hacl.K256.Field.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 44,
"start_col": 0,
"start_line": 42
} | module Hacl.K256.Field
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 BSeq = Lib.ByteSequence
module S = Spec.K256
include Hacl.Spec.K256.Field52.Definitions
module BI = Hacl.Spec.K256.Field52
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** Specialized bignum library with a radix-2^{52} *)
inline_for_extraction noextract
let nlimb = 5ul
inline_for_extraction noextract
let felem = lbuffer uint64 nlimb
noextract
let as_felem5 (h:mem) (e:felem) : GTot felem5 =
let open Lib.Sequence in
let s = as_seq h e in
(s.[0], s.[1], s.[2], s.[3], s.[4])
noextract
let as_nat (h:mem) (e:felem) : GTot nat =
as_nat5 (as_felem5 h e)
noextract
let feval (h:mem) (e:felem) : GTot S.felem = as_nat h e % S.prime | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Spec.K256.Field52.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.K256.Field.fsti"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52",
"short_module": "BI"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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"
} | false | f: Hacl.Spec.K256.Field52.Definitions.felem5 -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.K256.Field52.Definitions.felem5",
"Prims.l_and",
"Hacl.Spec.K256.Field52.Definitions.felem_fits5",
"FStar.Pervasives.Native.Mktuple5",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Hacl.Spec.K256.Field52.Definitions.as_nat5",
"Spec.K256.PointOps.prime",
"Prims.logical"
] | [] | false | false | false | true | true | let inv_fully_reduced5 (f: felem5) =
| felem_fits5 f (1, 1, 1, 1, 1) /\ as_nat5 f < S.prime | false |
|
Hacl.K256.Field.fsti | Hacl.K256.Field.inv_fully_reduced | val inv_fully_reduced : h: FStar.Monotonic.HyperStack.mem -> e: Hacl.K256.Field.felem -> Prims.logical | let inv_fully_reduced (h:mem) (e:felem) =
inv_fully_reduced5 (as_felem5 h e) | {
"file_name": "code/k256/Hacl.K256.Field.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 36,
"end_line": 48,
"start_col": 0,
"start_line": 47
} | module Hacl.K256.Field
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 BSeq = Lib.ByteSequence
module S = Spec.K256
include Hacl.Spec.K256.Field52.Definitions
module BI = Hacl.Spec.K256.Field52
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** Specialized bignum library with a radix-2^{52} *)
inline_for_extraction noextract
let nlimb = 5ul
inline_for_extraction noextract
let felem = lbuffer uint64 nlimb
noextract
let as_felem5 (h:mem) (e:felem) : GTot felem5 =
let open Lib.Sequence in
let s = as_seq h e in
(s.[0], s.[1], s.[2], s.[3], s.[4])
noextract
let as_nat (h:mem) (e:felem) : GTot nat =
as_nat5 (as_felem5 h e)
noextract
let feval (h:mem) (e:felem) : GTot S.felem = as_nat h e % S.prime
noextract
let inv_fully_reduced5 (f:felem5) =
felem_fits5 f (1,1,1,1,1) /\
as_nat5 f < S.prime | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Spec.K256.Field52.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.K256.Field.fsti"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52",
"short_module": "BI"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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"
} | false | h: FStar.Monotonic.HyperStack.mem -> e: Hacl.K256.Field.felem -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Hacl.K256.Field.felem",
"Hacl.K256.Field.inv_fully_reduced5",
"Hacl.K256.Field.as_felem5",
"Prims.logical"
] | [] | false | false | false | true | true | let inv_fully_reduced (h: mem) (e: felem) =
| inv_fully_reduced5 (as_felem5 h e) | false |
|
Hacl.K256.Field.fsti | Hacl.K256.Field.inv_lazy_reduced1_5 | val inv_lazy_reduced1_5 : f: Hacl.Spec.K256.Field52.Definitions.felem5 -> Prims.logical | let inv_lazy_reduced1_5 (f:felem5) =
felem_fits5 f (1,1,1,1,1) | {
"file_name": "code/k256/Hacl.K256.Field.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 53,
"start_col": 0,
"start_line": 52
} | module Hacl.K256.Field
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 BSeq = Lib.ByteSequence
module S = Spec.K256
include Hacl.Spec.K256.Field52.Definitions
module BI = Hacl.Spec.K256.Field52
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** Specialized bignum library with a radix-2^{52} *)
inline_for_extraction noextract
let nlimb = 5ul
inline_for_extraction noextract
let felem = lbuffer uint64 nlimb
noextract
let as_felem5 (h:mem) (e:felem) : GTot felem5 =
let open Lib.Sequence in
let s = as_seq h e in
(s.[0], s.[1], s.[2], s.[3], s.[4])
noextract
let as_nat (h:mem) (e:felem) : GTot nat =
as_nat5 (as_felem5 h e)
noextract
let feval (h:mem) (e:felem) : GTot S.felem = as_nat h e % S.prime
noextract
let inv_fully_reduced5 (f:felem5) =
felem_fits5 f (1,1,1,1,1) /\
as_nat5 f < S.prime
noextract
let inv_fully_reduced (h:mem) (e:felem) =
inv_fully_reduced5 (as_felem5 h e) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Spec.K256.Field52.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.K256.Field.fsti"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52",
"short_module": "BI"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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"
} | false | f: Hacl.Spec.K256.Field52.Definitions.felem5 -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.K256.Field52.Definitions.felem5",
"Hacl.Spec.K256.Field52.Definitions.felem_fits5",
"FStar.Pervasives.Native.Mktuple5",
"Prims.nat",
"Prims.logical"
] | [] | false | false | false | true | true | let inv_lazy_reduced1_5 (f: felem5) =
| felem_fits5 f (1, 1, 1, 1, 1) | false |
|
Hacl.K256.Field.fsti | Hacl.K256.Field.inv_lazy_reduced1 | val inv_lazy_reduced1 : h: FStar.Monotonic.HyperStack.mem -> e: Hacl.K256.Field.felem -> Prims.logical | let inv_lazy_reduced1 (h:mem) (e:felem) =
inv_lazy_reduced1_5 (as_felem5 h e) | {
"file_name": "code/k256/Hacl.K256.Field.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 57,
"start_col": 0,
"start_line": 56
} | module Hacl.K256.Field
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 BSeq = Lib.ByteSequence
module S = Spec.K256
include Hacl.Spec.K256.Field52.Definitions
module BI = Hacl.Spec.K256.Field52
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** Specialized bignum library with a radix-2^{52} *)
inline_for_extraction noextract
let nlimb = 5ul
inline_for_extraction noextract
let felem = lbuffer uint64 nlimb
noextract
let as_felem5 (h:mem) (e:felem) : GTot felem5 =
let open Lib.Sequence in
let s = as_seq h e in
(s.[0], s.[1], s.[2], s.[3], s.[4])
noextract
let as_nat (h:mem) (e:felem) : GTot nat =
as_nat5 (as_felem5 h e)
noextract
let feval (h:mem) (e:felem) : GTot S.felem = as_nat h e % S.prime
noextract
let inv_fully_reduced5 (f:felem5) =
felem_fits5 f (1,1,1,1,1) /\
as_nat5 f < S.prime
noextract
let inv_fully_reduced (h:mem) (e:felem) =
inv_fully_reduced5 (as_felem5 h e)
noextract
let inv_lazy_reduced1_5 (f:felem5) =
felem_fits5 f (1,1,1,1,1) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Spec.K256.Field52.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.K256.Field.fsti"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52",
"short_module": "BI"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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"
} | false | h: FStar.Monotonic.HyperStack.mem -> e: Hacl.K256.Field.felem -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Hacl.K256.Field.felem",
"Hacl.K256.Field.inv_lazy_reduced1_5",
"Hacl.K256.Field.as_felem5",
"Prims.logical"
] | [] | false | false | false | true | true | let inv_lazy_reduced1 (h: mem) (e: felem) =
| inv_lazy_reduced1_5 (as_felem5 h e) | false |
|
Hacl.K256.Field.fsti | Hacl.K256.Field.inv_lazy_reduced2 | val inv_lazy_reduced2 : h: FStar.Monotonic.HyperStack.mem -> e: Hacl.K256.Field.felem -> Prims.logical | let inv_lazy_reduced2 (h:mem) (e:felem) =
inv_lazy_reduced2_5 (as_felem5 h e) | {
"file_name": "code/k256/Hacl.K256.Field.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 65,
"start_col": 0,
"start_line": 64
} | module Hacl.K256.Field
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 BSeq = Lib.ByteSequence
module S = Spec.K256
include Hacl.Spec.K256.Field52.Definitions
module BI = Hacl.Spec.K256.Field52
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** Specialized bignum library with a radix-2^{52} *)
inline_for_extraction noextract
let nlimb = 5ul
inline_for_extraction noextract
let felem = lbuffer uint64 nlimb
noextract
let as_felem5 (h:mem) (e:felem) : GTot felem5 =
let open Lib.Sequence in
let s = as_seq h e in
(s.[0], s.[1], s.[2], s.[3], s.[4])
noextract
let as_nat (h:mem) (e:felem) : GTot nat =
as_nat5 (as_felem5 h e)
noextract
let feval (h:mem) (e:felem) : GTot S.felem = as_nat h e % S.prime
noextract
let inv_fully_reduced5 (f:felem5) =
felem_fits5 f (1,1,1,1,1) /\
as_nat5 f < S.prime
noextract
let inv_fully_reduced (h:mem) (e:felem) =
inv_fully_reduced5 (as_felem5 h e)
noextract
let inv_lazy_reduced1_5 (f:felem5) =
felem_fits5 f (1,1,1,1,1)
noextract
let inv_lazy_reduced1 (h:mem) (e:felem) =
inv_lazy_reduced1_5 (as_felem5 h e)
noextract
let inv_lazy_reduced2_5 (f:felem5) =
felem_fits5 f (1,1,1,1,2) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Spec.K256.Field52.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.K256.Field.fsti"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52",
"short_module": "BI"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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"
} | false | h: FStar.Monotonic.HyperStack.mem -> e: Hacl.K256.Field.felem -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Hacl.K256.Field.felem",
"Hacl.K256.Field.inv_lazy_reduced2_5",
"Hacl.K256.Field.as_felem5",
"Prims.logical"
] | [] | false | false | false | true | true | let inv_lazy_reduced2 (h: mem) (e: felem) =
| inv_lazy_reduced2_5 (as_felem5 h e) | false |
|
Hacl.K256.Field.fsti | Hacl.K256.Field.inv_lazy_reduced2_5 | val inv_lazy_reduced2_5 : f: Hacl.Spec.K256.Field52.Definitions.felem5 -> Prims.logical | let inv_lazy_reduced2_5 (f:felem5) =
felem_fits5 f (1,1,1,1,2) | {
"file_name": "code/k256/Hacl.K256.Field.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 27,
"end_line": 61,
"start_col": 0,
"start_line": 60
} | module Hacl.K256.Field
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 BSeq = Lib.ByteSequence
module S = Spec.K256
include Hacl.Spec.K256.Field52.Definitions
module BI = Hacl.Spec.K256.Field52
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** Specialized bignum library with a radix-2^{52} *)
inline_for_extraction noextract
let nlimb = 5ul
inline_for_extraction noextract
let felem = lbuffer uint64 nlimb
noextract
let as_felem5 (h:mem) (e:felem) : GTot felem5 =
let open Lib.Sequence in
let s = as_seq h e in
(s.[0], s.[1], s.[2], s.[3], s.[4])
noextract
let as_nat (h:mem) (e:felem) : GTot nat =
as_nat5 (as_felem5 h e)
noextract
let feval (h:mem) (e:felem) : GTot S.felem = as_nat h e % S.prime
noextract
let inv_fully_reduced5 (f:felem5) =
felem_fits5 f (1,1,1,1,1) /\
as_nat5 f < S.prime
noextract
let inv_fully_reduced (h:mem) (e:felem) =
inv_fully_reduced5 (as_felem5 h e)
noextract
let inv_lazy_reduced1_5 (f:felem5) =
felem_fits5 f (1,1,1,1,1)
noextract
let inv_lazy_reduced1 (h:mem) (e:felem) =
inv_lazy_reduced1_5 (as_felem5 h e) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Spec.K256.Field52.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.K256.Field.fsti"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52",
"short_module": "BI"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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"
} | false | f: Hacl.Spec.K256.Field52.Definitions.felem5 -> Prims.logical | Prims.Tot | [
"total"
] | [] | [
"Hacl.Spec.K256.Field52.Definitions.felem5",
"Hacl.Spec.K256.Field52.Definitions.felem_fits5",
"FStar.Pervasives.Native.Mktuple5",
"Prims.nat",
"Prims.logical"
] | [] | false | false | false | true | true | let inv_lazy_reduced2_5 (f: felem5) =
| felem_fits5 f (1, 1, 1, 1, 2) | false |
|
FStar.NMSTTotal.fst | FStar.NMSTTotal.return | val return (a: Type) (x: a) (state: Type u#2) (rel: P.preorder state)
: repr a state rel (fun _ -> True) (fun s0 r s1 -> r == x /\ s0 == s1) | val return (a: Type) (x: a) (state: Type u#2) (rel: P.preorder state)
: repr a state rel (fun _ -> True) (fun s0 r s1 -> r == x /\ s0 == s1) | let return (a:Type) (x:a) (state:Type u#2) (rel:P.preorder state)
: repr a state rel (fun _ -> True) (fun s0 r s1 -> r == x /\ s0 == s1)
=
fun (_, n) -> x, n | {
"file_name": "ulib/experimental/FStar.NMSTTotal.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 20,
"end_line": 42,
"start_col": 0,
"start_line": 39
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.NMSTTotal
module W = FStar.Witnessed.Core
module P = FStar.Preorder
module M = FStar.MSTTotal
open FStar.Monotonic.Pure
type tape = nat -> bool
type repr
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
=
(tape & nat) ->
M.MSTATETOT (a & nat) state rel req (fun s0 (x, _) s1 -> ens s0 x s1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Witnessed.Core.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.NMSTTotal.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Witnessed.Core",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type -> x: a -> state: Type -> rel: FStar.Preorder.preorder state
-> FStar.NMSTTotal.repr a state rel (fun _ -> Prims.l_True) (fun s0 r s1 -> r == x /\ s0 == s1) | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.Pervasives.Native.tuple2",
"FStar.NMSTTotal.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"FStar.NMSTTotal.repr",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2"
] | [] | false | false | false | false | false | let return (a: Type) (x: a) (state: Type u#2) (rel: P.preorder state)
: repr a state rel (fun _ -> True) (fun s0 r s1 -> r == x /\ s0 == s1) =
| fun (_, n) -> x, n | false |
Hacl.Impl.Poly1305.Bignum128.fst | Hacl.Impl.Poly1305.Bignum128.add_mod_small | val add_mod_small: a:nat -> b:nat -> n:pos -> Lemma
(requires a % n + b % n < n)
(ensures a % n + b % n == (a + b) % n) | val add_mod_small: a:nat -> b:nat -> n:pos -> Lemma
(requires a % n + b % n < n)
(ensures a % n + b % n == (a + b) % n) | let add_mod_small a b n =
FStar.Math.Lemmas.modulo_lemma (a % n + b % n) n;
assert (a % n + b % n == (a % n + b % n) % n);
FStar.Math.Lemmas.lemma_mod_plus_distr_l a (b % n) n;
FStar.Math.Lemmas.lemma_mod_plus_distr_r a b n | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Bignum128.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 73,
"start_col": 0,
"start_line": 69
} | module Hacl.Impl.Poly1305.Bignum128
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Poly1305.Lemmas
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
friend FStar.UInt128
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let uints64_from_bytes_le b =
let h0 = ST.get () in
let lo = uint_from_bytes_le #U64 (sub b 0ul 8ul) in
let hi = uint_from_bytes_le #U64 (sub b 8ul 8ul) in
uint_from_bytes_le_lemma (as_seq h0 b);
lo, hi
let uints64_to_bytes_le b r0 r1 =
let h0 = ST.get () in
update_sub_f h0 b 0ul 8ul
(fun h -> BSeq.uint_to_bytes_le #U64 r0)
(fun _ -> uint_to_bytes_le (sub b 0ul 8ul) r0);
let h1 = ST.get () in
update_sub_f h1 b 8ul 8ul
(fun h -> BSeq.uint_to_bytes_le #U64 r1)
(fun _ -> uint_to_bytes_le (sub b 8ul 8ul) r1);
//uint_to_bytes_le (sub b 0ul 8ul) r0;
//uint_to_bytes_le (sub b 8ul 8ul) r1;
let h2 = ST.get () in
uints64_to_bytes_le_lemma r0 r1;
LSeq.eq_intro (LSeq.sub (as_seq h2 b) 0 8) (BSeq.uint_to_bytes_le #U64 r0);
LSeq.lemma_concat2
8 (BSeq.uint_to_bytes_le #U64 r0)
8 (BSeq.uint_to_bytes_le #U64 r1) (as_seq h2 b)
val constant_time_carry_ok: r0:uint64 -> b0:uint64 ->
Lemma (let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
v c == (if v r0 < v b0 then 1 else 0))
let constant_time_carry_ok r0 b0 =
let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
let r0' = Lib.RawIntTypes.u64_to_UInt64 r0 in
let b0' = Lib.RawIntTypes.u64_to_UInt64 b0 in
let c' = FStar.UInt128.constant_time_carry r0' b0' in
logxor_spec r0 b0;
logxor_spec (r0 -. b0) b0;
logor_spec (r0 ^. b0) ((r0 -. b0) ^. b0);
logxor_spec r0 ((r0 ^. b0) |. ((r0 -. b0) ^. b0));
assert (v c' == v c);
FStar.UInt128.constant_time_carry_ok r0' b0'
val add_mod_small: a:nat -> b:nat -> n:pos -> Lemma
(requires a % n + b % n < n)
(ensures a % n + b % n == (a + b) % n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt128.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Poly1305.Bignum128.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Prims.nat -> b: Prims.nat -> n: Prims.pos
-> FStar.Pervasives.Lemma (requires a % n + b % n < n) (ensures a % n + b % n == (a + b) % n) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Prims.nat",
"Prims.pos",
"FStar.Math.Lemmas.lemma_mod_plus_distr_r",
"Prims.unit",
"FStar.Math.Lemmas.lemma_mod_plus_distr_l",
"Prims.op_Modulus",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"FStar.Math.Lemmas.modulo_lemma"
] | [] | true | false | true | false | false | let add_mod_small a b n =
| FStar.Math.Lemmas.modulo_lemma (a % n + b % n) n;
assert (a % n + b % n == (a % n + b % n) % n);
FStar.Math.Lemmas.lemma_mod_plus_distr_l a (b % n) n;
FStar.Math.Lemmas.lemma_mod_plus_distr_r a b n | false |
FStar.NMSTTotal.fst | FStar.NMSTTotal.subcomp | val subcomp
(a: Type)
(state: Type u#2)
(rel: P.preorder state)
(req_f: M.pre_t state)
(ens_f: M.post_t state a)
(req_g: M.pre_t state)
(ens_g: M.post_t state a)
(f: repr a state rel req_f ens_f)
: Pure (repr a state rel req_g ens_g)
(requires
(forall s. req_g s ==> req_f s) /\
(forall s0 x s1. (req_g s0 /\ ens_f s0 x s1) ==> ens_g s0 x s1))
(ensures fun _ -> True) | val subcomp
(a: Type)
(state: Type u#2)
(rel: P.preorder state)
(req_f: M.pre_t state)
(ens_f: M.post_t state a)
(req_g: M.pre_t state)
(ens_g: M.post_t state a)
(f: repr a state rel req_f ens_f)
: Pure (repr a state rel req_g ens_g)
(requires
(forall s. req_g s ==> req_f s) /\
(forall s0 x s1. (req_g s0 /\ ens_f s0 x s1) ==> ens_g s0 x s1))
(ensures fun _ -> True) | let subcomp
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:M.pre_t state)
(ens_g:M.post_t state a)
(f:repr a state rel req_f ens_f)
: Pure (repr a state rel req_g ens_g)
(requires
(forall s. req_g s ==> req_f s) /\
(forall s0 x s1. (req_g s0 /\ ens_f s0 x s1) ==> ens_g s0 x s1))
(ensures fun _ -> True)
=
f | {
"file_name": "ulib/experimental/FStar.NMSTTotal.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 3,
"end_line": 78,
"start_col": 0,
"start_line": 63
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.NMSTTotal
module W = FStar.Witnessed.Core
module P = FStar.Preorder
module M = FStar.MSTTotal
open FStar.Monotonic.Pure
type tape = nat -> bool
type repr
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
=
(tape & nat) ->
M.MSTATETOT (a & nat) state rel req (fun s0 (x, _) s1 -> ens s0 x s1)
let return (a:Type) (x:a) (state:Type u#2) (rel:P.preorder state)
: repr a state rel (fun _ -> True) (fun s0 r s1 -> r == x /\ s0 == s1)
=
fun (_, n) -> x, n
let bind
(a:Type)
(b:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:a -> M.pre_t state)
(ens_g:a -> M.post_t state b)
(f:repr a state rel req_f ens_f)
(g:(x:a -> repr b state rel (req_g x) (ens_g x)))
: repr b state rel
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2))
=
fun (t, n) ->
let x, n1 = f (t, n) in
(g x) (t, n1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Witnessed.Core.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.NMSTTotal.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Witnessed.Core",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type ->
state: Type ->
rel: FStar.Preorder.preorder state ->
req_f: FStar.MSTTotal.pre_t state ->
ens_f: FStar.MSTTotal.post_t state a ->
req_g: FStar.MSTTotal.pre_t state ->
ens_g: FStar.MSTTotal.post_t state a ->
f: FStar.NMSTTotal.repr a state rel req_f ens_f
-> Prims.Pure (FStar.NMSTTotal.repr a state rel req_g ens_g) | Prims.Pure | [] | [] | [
"FStar.Preorder.preorder",
"FStar.MSTTotal.pre_t",
"FStar.MSTTotal.post_t",
"FStar.NMSTTotal.repr",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_True"
] | [] | false | false | false | false | false | let subcomp
(a: Type)
(state: Type u#2)
(rel: P.preorder state)
(req_f: M.pre_t state)
(ens_f: M.post_t state a)
(req_g: M.pre_t state)
(ens_g: M.post_t state a)
(f: repr a state rel req_f ens_f)
: Pure (repr a state rel req_g ens_g)
(requires
(forall s. req_g s ==> req_f s) /\
(forall s0 x s1. (req_g s0 /\ ens_f s0 x s1) ==> ens_g s0 x s1))
(ensures fun _ -> True) =
| f | false |
FStar.NMSTTotal.fst | FStar.NMSTTotal.bind | val bind
(a b: Type)
(state: Type u#2)
(rel: P.preorder state)
(req_f: M.pre_t state)
(ens_f: M.post_t state a)
(req_g: (a -> M.pre_t state))
(ens_g: (a -> M.post_t state b))
(f: repr a state rel req_f ens_f)
(g: (x: a -> repr b state rel (req_g x) (ens_g x)))
: repr b
state
rel
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2)) | val bind
(a b: Type)
(state: Type u#2)
(rel: P.preorder state)
(req_f: M.pre_t state)
(ens_f: M.post_t state a)
(req_g: (a -> M.pre_t state))
(ens_g: (a -> M.post_t state b))
(f: repr a state rel req_f ens_f)
(g: (x: a -> repr b state rel (req_g x) (ens_g x)))
: repr b
state
rel
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2)) | let bind
(a:Type)
(b:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:a -> M.pre_t state)
(ens_g:a -> M.post_t state b)
(f:repr a state rel req_f ens_f)
(g:(x:a -> repr b state rel (req_g x) (ens_g x)))
: repr b state rel
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2))
=
fun (t, n) ->
let x, n1 = f (t, n) in
(g x) (t, n1) | {
"file_name": "ulib/experimental/FStar.NMSTTotal.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 17,
"end_line": 61,
"start_col": 0,
"start_line": 44
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.NMSTTotal
module W = FStar.Witnessed.Core
module P = FStar.Preorder
module M = FStar.MSTTotal
open FStar.Monotonic.Pure
type tape = nat -> bool
type repr
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
=
(tape & nat) ->
M.MSTATETOT (a & nat) state rel req (fun s0 (x, _) s1 -> ens s0 x s1)
let return (a:Type) (x:a) (state:Type u#2) (rel:P.preorder state)
: repr a state rel (fun _ -> True) (fun s0 r s1 -> r == x /\ s0 == s1)
=
fun (_, n) -> x, n | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Witnessed.Core.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.NMSTTotal.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Witnessed.Core",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type ->
b: Type ->
state: Type ->
rel: FStar.Preorder.preorder state ->
req_f: FStar.MSTTotal.pre_t state ->
ens_f: FStar.MSTTotal.post_t state a ->
req_g: (_: a -> FStar.MSTTotal.pre_t state) ->
ens_g: (_: a -> FStar.MSTTotal.post_t state b) ->
f: FStar.NMSTTotal.repr a state rel req_f ens_f ->
g: (x: a -> FStar.NMSTTotal.repr b state rel (req_g x) (ens_g x))
-> FStar.NMSTTotal.repr b
state
rel
(fun s0 -> req_f s0 /\ (forall (x: a) (s1: state). ens_f s0 x s1 ==> req_g x s1))
(fun s0 r s2 ->
req_f s0 /\ (exists (x: a) (s1: state). ens_f s0 x s1 /\ req_g x s1 /\ ens_g x s1 r s2)) | Prims.Tot | [
"total"
] | [] | [
"FStar.Preorder.preorder",
"FStar.MSTTotal.pre_t",
"FStar.MSTTotal.post_t",
"FStar.NMSTTotal.repr",
"FStar.Pervasives.Native.tuple2",
"FStar.NMSTTotal.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"Prims.l_and",
"Prims.l_Forall",
"Prims.l_imp",
"Prims.l_Exists"
] | [] | false | false | false | false | false | let bind
(a b: Type)
(state: Type u#2)
(rel: P.preorder state)
(req_f: M.pre_t state)
(ens_f: M.post_t state a)
(req_g: (a -> M.pre_t state))
(ens_g: (a -> M.post_t state b))
(f: repr a state rel req_f ens_f)
(g: (x: a -> repr b state rel (req_g x) (ens_g x)))
: repr b
state
rel
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2)) =
| fun (t, n) ->
let x, n1 = f (t, n) in
(g x) (t, n1) | false |
FStar.NMSTTotal.fst | FStar.NMSTTotal.get | val get: #state: Type u#2 -> #rel: P.preorder state -> Prims.unit
-> NMSTATETOT state state rel (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) | val get: #state: Type u#2 -> #rel: P.preorder state -> Prims.unit
-> NMSTATETOT state state rel (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) | let get (#state:Type u#2) (#rel:P.preorder state) ()
: NMSTATETOT state state rel
(fun _ -> True)
(fun s0 s s1 -> s0 == s /\ s == s1)
=
NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.get (), n) | {
"file_name": "ulib/experimental/FStar.NMSTTotal.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 56,
"end_line": 115,
"start_col": 0,
"start_line": 110
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.NMSTTotal
module W = FStar.Witnessed.Core
module P = FStar.Preorder
module M = FStar.MSTTotal
open FStar.Monotonic.Pure
type tape = nat -> bool
type repr
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
=
(tape & nat) ->
M.MSTATETOT (a & nat) state rel req (fun s0 (x, _) s1 -> ens s0 x s1)
let return (a:Type) (x:a) (state:Type u#2) (rel:P.preorder state)
: repr a state rel (fun _ -> True) (fun s0 r s1 -> r == x /\ s0 == s1)
=
fun (_, n) -> x, n
let bind
(a:Type)
(b:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:a -> M.pre_t state)
(ens_g:a -> M.post_t state b)
(f:repr a state rel req_f ens_f)
(g:(x:a -> repr b state rel (req_g x) (ens_g x)))
: repr b state rel
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2))
=
fun (t, n) ->
let x, n1 = f (t, n) in
(g x) (t, n1)
let subcomp
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:M.pre_t state)
(ens_g:M.post_t state a)
(f:repr a state rel req_f ens_f)
: Pure (repr a state rel req_g ens_g)
(requires
(forall s. req_g s ==> req_f s) /\
(forall s0 x s1. (req_g s0 /\ ens_f s0 x s1) ==> ens_g s0 x s1))
(ensures fun _ -> True)
=
f
let if_then_else
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_then:M.pre_t state)
(ens_then:M.post_t state a)
(req_else:M.pre_t state)
(ens_else:M.post_t state a)
(f:repr a state rel req_then ens_then)
(g:repr a state rel req_else ens_else)
(p:bool)
: Type
=
repr a state rel
(fun s0 -> (p ==> req_then s0) /\ ((~ p) ==> req_else s0))
(fun s0 x s1 -> (p ==> ens_then s0 x s1) /\ ((~ p) ==> ens_else s0 x s1))
[@@ primitive_extraction]
total
reflectable
effect {
NMSTATETOT (a:Type)
([@@@ effect_param] state:Type u#2)
([@@@ effect_param] rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
with { repr; return; bind; subcomp; if_then_else }
} | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Witnessed.Core.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.NMSTTotal.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Witnessed.Core",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.NMSTTotal.NMSTATETOT state | FStar.NMSTTotal.NMSTATETOT | [] | [] | [
"FStar.Preorder.preorder",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"FStar.NMSTTotal.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"FStar.MSTTotal.get",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2"
] | [] | false | true | false | false | false | let get (#state: Type u#2) (#rel: P.preorder state) ()
: NMSTATETOT state state rel (fun _ -> True) (fun s0 s s1 -> s0 == s /\ s == s1) =
| NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.get (), n) | false |
Hacl.Bignum.Karatsuba.fst | Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_open | val bn_karatsuba_sqr_open: #t:limb_t -> (self: unit -> bn_karatsuba_sqr_st t) -> bn_karatsuba_sqr_st t | val bn_karatsuba_sqr_open: #t:limb_t -> (self: unit -> bn_karatsuba_sqr_st t) -> bn_karatsuba_sqr_st t | let bn_karatsuba_sqr_open #t (self: unit -> bn_karatsuba_sqr_st t) len a tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_sqr_]]
(K.bn_karatsuba_sqr_ (v len) (as_seq h0 a));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_sqr_u len a res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let t0 = sub tmp 0ul len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
LowStar.Ignore.ignore c0;
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 tmp1 r01;
self () len2 a1 tmp1 r23;
let c = bn_karatsuba_last_sqr len tmp res in
LowStar.Ignore.ignore c;
() end | {
"file_name": "code/bignum/Hacl.Bignum.Karatsuba.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 370,
"start_col": 0,
"start_line": 343
} | module Hacl.Bignum.Karatsuba
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
open Hacl.Bignum.Base
open Hacl.Impl.Lib
open Hacl.Bignum.Addition
open Hacl.Bignum.Multiplication
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module B = LowStar.Buffer
module Loops = Lib.LoopCombinators
module K = Hacl.Spec.Bignum.Karatsuba
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_mul_threshold = size K.bn_mul_threshold
inline_for_extraction noextract
val bn_sign_abs:
#t:limb_t
-> #aLen:size_t
-> a:lbignum t aLen
-> b:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (carry t)
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
eq_or_disjoint a b /\ disjoint a res /\ disjoint b res /\
disjoint a tmp /\ disjoint b tmp /\ disjoint tmp res)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(c, as_seq h1 res) == K.bn_sign_abs (as_seq h0 a) (as_seq h0 b))
let bn_sign_abs #t #aLen a b tmp res =
let c0 = bn_sub_eq_len_u aLen a b tmp in
let c1 = bn_sub_eq_len_u aLen b a res in
map2T aLen res (mask_select (uint #t 0 -. c0)) res tmp;
LowStar.Ignore.ignore c1;
c0
inline_for_extraction noextract
val bn_middle_karatsuba:
#t:limb_t
-> #aLen:size_t
-> c0:carry t
-> c1:carry t
-> c2:carry t
-> t01:lbignum t aLen
-> t23:lbignum t aLen
-> tmp:lbignum t aLen
-> res:lbignum t aLen ->
Stack (limb t)
(requires fun h ->
live h t01 /\ live h t23 /\ live h tmp /\ live h res /\
disjoint t01 t23 /\ disjoint tmp res /\ disjoint t01 res /\
disjoint t01 tmp /\ disjoint t23 tmp /\ disjoint t23 res)
(ensures fun h0 c h1 -> modifies (loc tmp |+| loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_middle_karatsuba c0 c1 c2 (as_seq h0 t01) (as_seq h0 t23))
let bn_middle_karatsuba #t #aLen c0 c1 c2 t01 t23 tmp res =
let c_sign = c0 ^. c1 in
let c3 = bn_sub_eq_len_u aLen t01 t23 tmp in let c3 = c2 -. c3 in
let c4 = bn_add_eq_len_u aLen t01 t23 res in let c4 = c2 +. c4 in
let mask = uint #t 0 -. c_sign in
map2T aLen res (mask_select mask) res tmp;
mask_select mask c4 c3
inline_for_extraction noextract
val bn_lshift_add_in_place:
#t:limb_t
-> #aLen:size_t{0 < v aLen}
-> a:lbignum t aLen
-> b1:limb t
-> i:size_t{v i + 1 <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add (as_seq h0 a) b1 (v i))
let bn_lshift_add_in_place #t #aLen a b1 i =
let r = sub a i (aLen -! i) in
let h0 = ST.get () in
update_sub_f_carry h0 a i (aLen -! i)
(fun h -> Hacl.Spec.Bignum.Addition.bn_add1 (as_seq h0 r) b1)
(fun _ -> bn_add1 (aLen -! i) r b1 r)
inline_for_extraction noextract
val bn_lshift_add_early_stop_in_place:
#t:limb_t
-> #aLen:size_t
-> #bLen:size_t
-> a:lbignum t aLen
-> b:lbignum t bLen
-> i:size_t{v i + v bLen <= v aLen} ->
Stack (carry t)
(requires fun h -> live h a /\ live h b /\ disjoint a b)
(ensures fun h0 c h1 -> modifies (loc a) h0 h1 /\
(c, as_seq h1 a) == K.bn_lshift_add_early_stop (as_seq h0 a) (as_seq h0 b) (v i))
let bn_lshift_add_early_stop_in_place #t #aLen #bLen a b i =
let r = sub a i bLen in
let h0 = ST.get () in
let c =
update_sub_f_carry h0 a i bLen
(fun h -> Hacl.Spec.Bignum.Addition.bn_add (as_seq h0 r) (as_seq h0 b))
(fun _ -> bn_add_eq_len_u bLen r b r) in
c
inline_for_extraction noextract
val bn_karatsuba_res:
#t:limb_t
-> #aLen:size_t{2 * v aLen <= max_size_t /\ 0 < v aLen}
-> r01:lbignum t aLen
-> r23:lbignum t aLen
-> c5:limb t
-> t45:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack (carry t)
(requires fun h ->
live h r01 /\ live h r23 /\ live h t45 /\ live h res /\ disjoint t45 res /\
as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23))
(ensures fun h0 c h1 -> modifies (loc res) h0 h1 /\
(c, as_seq h1 res) == K.bn_karatsuba_res (as_seq h0 r01) (as_seq h0 r23) c5 (as_seq h0 t45))
let bn_karatsuba_res #t #aLen r01 r23 c5 t45 res =
let aLen2 = aLen /. 2ul in
[@inline_let] let resLen = aLen +! aLen in
let c6 = bn_lshift_add_early_stop_in_place res t45 aLen2 in
let c7 = c5 +. c6 in
let c8 = bn_lshift_add_in_place res c7 (aLen +! aLen2) in
c8
inline_for_extraction noextract
val bn_karatsuba_last:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> c0:carry t
-> c1:carry t
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba c0 c1 sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last #t aLen c0 c1 tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let t67 = sub tmp (3ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c5 = bn_middle_karatsuba c0 c1 c2 t01 t23 t67 t45 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
#push-options "--z3rlimit 150"
(* from Jonathan:
let karatsuba_t = dst:bignum -> a:bignum -> b:bignum -> Stack unit ensures dst = a * b
inline_for_extraction
let karatsuba_open (self: unit -> karastuba_t): fun dst a b ->
... self () dst' a' b' ...
let rec karatsuba () = karatsuba_open karastuba
*)
inline_for_extraction noextract
let bn_karatsuba_mul_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t}
-> a:lbignum t len
-> b:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint tmp b /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b))
inline_for_extraction noextract
val bn_karatsuba_mul_open: #t:limb_t -> (self: unit -> bn_karatsuba_mul_st t) -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_open #t (self: unit -> bn_karatsuba_mul_st t) len a b tmp res =
let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_mul_]]
(K.bn_karatsuba_mul_ (v len) (as_seq h0 a) (as_seq h0 b));
if len <. bn_mul_threshold || len %. 2ul =. 1ul then
bn_mul_u len a len b res
else begin
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let b0 = sub b 0ul len2 in
let b1 = sub b len2 len2 in
// tmp = [ t0_len2; t1_len2; ..]
let t0 = sub tmp 0ul len2 in
let t1 = sub tmp len2 len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
let c1 = bn_sign_abs b0 b1 tmp' t1 in
// tmp = [ t0_len2; t1_len2; t23_len; ..]
(**) let h0 = ST.get () in
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 t1 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 b0 tmp1 r01;
self () len2 a1 b1 tmp1 r23;
let c = bn_karatsuba_last len c0 c1 tmp res in
LowStar.Ignore.ignore c;
() end
val bn_karatsuba_mul_uint32 : unit -> bn_karatsuba_mul_st U32
let rec bn_karatsuba_mul_uint32 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint32 aLen a b tmp res
val bn_karatsuba_mul_uint64 : unit -> bn_karatsuba_mul_st U64
let rec bn_karatsuba_mul_uint64 () aLen a b tmp res =
bn_karatsuba_mul_open bn_karatsuba_mul_uint64 aLen a b tmp res
inline_for_extraction noextract
val bn_karatsuba_mul_: #t:limb_t -> bn_karatsuba_mul_st t
let bn_karatsuba_mul_ #t =
match t with
| U32 -> bn_karatsuba_mul_uint32 ()
| U64 -> bn_karatsuba_mul_uint64 ()
//TODO: pass tmp as a parameter?
inline_for_extraction noextract
val bn_karatsuba_mul:
#t:limb_t
-> aLen:size_t{0 < v aLen /\ 4 * v aLen <= max_size_t}
-> a:lbignum t aLen
-> b:lbignum t aLen
-> res:lbignum t (aLen +! aLen) ->
Stack unit
(requires fun h ->
live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ eq_or_disjoint a b)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_mul (as_seq h0 a) (as_seq h0 b))
let bn_karatsuba_mul #t aLen a b res =
push_frame ();
let tmp = create (4ul *! aLen) (uint #t 0) in
bn_karatsuba_mul_ aLen a b tmp res;
pop_frame ()
inline_for_extraction noextract
val bn_karatsuba_last_sqr:
#t:limb_t
-> aLen:size_t{4 * v aLen <= max_size_t /\ v aLen % 2 = 0 /\ 0 < v aLen}
-> tmp:lbignum t (4ul *! aLen)
-> res:lbignum t (aLen +! aLen) ->
Stack (limb t)
(requires fun h -> live h res /\ live h tmp /\ disjoint res tmp)
(ensures fun h0 c h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
(let sr01 = LSeq.sub (as_seq h0 res) 0 (v aLen) in
let sr23 = LSeq.sub (as_seq h0 res) (v aLen) (v aLen) in
let st23 = LSeq.sub (as_seq h0 tmp) (v aLen) (v aLen) in
let sc2, st01 = Hacl.Spec.Bignum.Addition.bn_add sr01 sr23 in
let sc5, sres = K.bn_middle_karatsuba_sqr sc2 st01 st23 in
let sc, sres = K.bn_karatsuba_res sr01 sr23 sc5 sres in
(c, as_seq h1 res) == (sc, sres)))
let bn_karatsuba_last_sqr #t aLen tmp res =
let r01 = sub res 0ul aLen in
let r23 = sub res aLen aLen in
(**) let h = ST.get () in
(**) LSeq.lemma_concat2 (v aLen) (as_seq h r01) (v aLen) (as_seq h r23) (as_seq h res);
(**) assert (as_seq h res == LSeq.concat (as_seq h r01) (as_seq h r23));
let t01 = sub tmp 0ul aLen in
let t23 = sub tmp aLen aLen in
let t45 = sub tmp (2ul *! aLen) aLen in
let c2 = bn_add_eq_len_u aLen r01 r23 t01 in
let c3 = bn_sub_eq_len_u aLen t01 t23 t45 in
let c5 = c2 -. c3 in
let c = bn_karatsuba_res r01 r23 c5 t45 res in
c
inline_for_extraction noextract
let bn_karatsuba_sqr_st (t:limb_t) =
len:size_t{4 * v len <= max_size_t /\ 0 < v len}
-> a:lbignum t len
-> tmp:lbignum t (4ul *! len)
-> res:lbignum t (len +! len) ->
Stack unit
(requires fun h ->
live h a /\ live h res /\ live h tmp /\
disjoint res tmp /\ disjoint tmp a /\ disjoint res a)
(ensures fun h0 _ h1 -> modifies (loc res |+| loc tmp) h0 h1 /\
as_seq h1 res == K.bn_karatsuba_sqr_ (v len) (as_seq h0 a))
inline_for_extraction noextract | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Ignore.fsti.checked",
"LowStar.Buffer.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Karatsuba.fst.checked",
"Hacl.Spec.Bignum.Addition.fst.checked",
"Hacl.Impl.Lib.fst.checked",
"Hacl.Bignum.Multiplication.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Base.fst.checked",
"Hacl.Bignum.Addition.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Karatsuba.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Karatsuba",
"short_module": "K"
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Multiplication",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Addition",
"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": "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.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
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 150,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | self: (self: Prims.unit -> Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_st t)
-> Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_st t | Prims.Tot | [
"total"
] | [] | [
"Hacl.Bignum.Definitions.limb_t",
"Prims.unit",
"Hacl.Bignum.Karatsuba.bn_karatsuba_sqr_st",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.max_size_t",
"Prims.op_LessThan",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.op_Star_Bang",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Plus_Bang",
"Prims.op_BarBar",
"Lib.IntTypes.op_Less_Dot",
"Hacl.Bignum.Karatsuba.bn_mul_threshold",
"Lib.IntTypes.op_Equals_Dot",
"Lib.IntTypes.op_Percent_Dot",
"Hacl.Bignum.Multiplication.bn_sqr_u",
"Prims.bool",
"LowStar.Ignore.ignore",
"Hacl.Bignum.Definitions.limb",
"Hacl.Bignum.Karatsuba.bn_karatsuba_last_sqr",
"Lib.Buffer.lbuffer_t",
"Lib.Buffer.MUT",
"Lib.Buffer.sub",
"Lib.IntTypes.add",
"Hacl.Spec.Bignum.Base.carry",
"Hacl.Bignum.Karatsuba.bn_sign_abs",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Slash_Dot",
"FStar.Pervasives.norm_spec",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.zeta",
"FStar.Pervasives.iota",
"FStar.Pervasives.primops",
"FStar.Pervasives.delta_only",
"Prims.string",
"Prims.Nil",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.op_Addition",
"Prims.eq2",
"Prims.int",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.Buffer.as_seq",
"Hacl.Spec.Bignum.Karatsuba.bn_karatsuba_sqr_",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | false | false | false | false | let bn_karatsuba_sqr_open #t (self: (unit -> bn_karatsuba_sqr_st t)) len a tmp res =
| let h0 = ST.get () in
norm_spec [zeta; iota; primops; delta_only [`%K.bn_karatsuba_sqr_]]
(K.bn_karatsuba_sqr_ (v len) (as_seq h0 a));
if len <. bn_mul_threshold || len %. 2ul =. 1ul
then bn_sqr_u len a res
else
let len2 = len /. 2ul in
let a0 = sub a 0ul len2 in
let a1 = sub a len2 len2 in
let t0 = sub tmp 0ul len2 in
let tmp' = sub tmp len len2 in
let c0 = bn_sign_abs a0 a1 tmp' t0 in
LowStar.Ignore.ignore c0;
let t23 = sub tmp len len in
let tmp1 = sub tmp (len +! len) (len +! len) in
self () len2 t0 tmp1 t23;
let r01 = sub res 0ul len in
let r23 = sub res len len in
self () len2 a0 tmp1 r01;
self () len2 a1 tmp1 r23;
let c = bn_karatsuba_last_sqr len tmp res in
LowStar.Ignore.ignore c;
() | false |
FStar.NMSTTotal.fst | FStar.NMSTTotal.sample | val sample: #state: Type u#2 -> #rel: P.preorder state -> Prims.unit
-> NMSTATETOT bool state rel (fun _ -> True) (fun s0 _ s1 -> s0 == s1) | val sample: #state: Type u#2 -> #rel: P.preorder state -> Prims.unit
-> NMSTATETOT bool state rel (fun _ -> True) (fun s0 _ s1 -> s0 == s1) | let sample (#state:Type u#2) (#rel:P.preorder state) ()
: NMSTATETOT bool state rel
(fun _ -> True)
(fun s0 _ s1 -> s0 == s1)
=
NMSTATETOT?.reflect (fun (t, n) -> t n, n+1) | {
"file_name": "ulib/experimental/FStar.NMSTTotal.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 46,
"end_line": 151,
"start_col": 0,
"start_line": 146
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.NMSTTotal
module W = FStar.Witnessed.Core
module P = FStar.Preorder
module M = FStar.MSTTotal
open FStar.Monotonic.Pure
type tape = nat -> bool
type repr
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
=
(tape & nat) ->
M.MSTATETOT (a & nat) state rel req (fun s0 (x, _) s1 -> ens s0 x s1)
let return (a:Type) (x:a) (state:Type u#2) (rel:P.preorder state)
: repr a state rel (fun _ -> True) (fun s0 r s1 -> r == x /\ s0 == s1)
=
fun (_, n) -> x, n
let bind
(a:Type)
(b:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:a -> M.pre_t state)
(ens_g:a -> M.post_t state b)
(f:repr a state rel req_f ens_f)
(g:(x:a -> repr b state rel (req_g x) (ens_g x)))
: repr b state rel
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2))
=
fun (t, n) ->
let x, n1 = f (t, n) in
(g x) (t, n1)
let subcomp
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:M.pre_t state)
(ens_g:M.post_t state a)
(f:repr a state rel req_f ens_f)
: Pure (repr a state rel req_g ens_g)
(requires
(forall s. req_g s ==> req_f s) /\
(forall s0 x s1. (req_g s0 /\ ens_f s0 x s1) ==> ens_g s0 x s1))
(ensures fun _ -> True)
=
f
let if_then_else
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_then:M.pre_t state)
(ens_then:M.post_t state a)
(req_else:M.pre_t state)
(ens_else:M.post_t state a)
(f:repr a state rel req_then ens_then)
(g:repr a state rel req_else ens_else)
(p:bool)
: Type
=
repr a state rel
(fun s0 -> (p ==> req_then s0) /\ ((~ p) ==> req_else s0))
(fun s0 x s1 -> (p ==> ens_then s0 x s1) /\ ((~ p) ==> ens_else s0 x s1))
[@@ primitive_extraction]
total
reflectable
effect {
NMSTATETOT (a:Type)
([@@@ effect_param] state:Type u#2)
([@@@ effect_param] rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
with { repr; return; bind; subcomp; if_then_else }
}
[@@ noextract_to "krml"]
let get (#state:Type u#2) (#rel:P.preorder state) ()
: NMSTATETOT state state rel
(fun _ -> True)
(fun s0 s s1 -> s0 == s /\ s == s1)
=
NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.get (), n)
[@@ noextract_to "krml"]
let put (#state:Type u#2) (#rel:P.preorder state) (s:state)
: NMSTATETOT unit state rel
(fun s0 -> rel s0 s)
(fun _ _ s1 -> s1 == s)
=
NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.put s, n)
[@@ noextract_to "krml"]
let witness (state:Type u#2) (rel:P.preorder state) (p:W.s_predicate state)
: NMSTATETOT (W.witnessed state rel p) state rel
(fun s0 -> p s0 /\ W.stable state rel p)
(fun s0 _ s1 -> s0 == s1)
=
NMSTATETOT?.reflect (fun (_, n) -> M.witness state rel p, n)
[@@ noextract_to "krml"]
let recall (state:Type u#2)
(rel:P.preorder state)
(p:W.s_predicate state)
(w:W.witnessed state rel p)
: NMSTATETOT unit state rel
(fun _ -> True)
(fun s0 _ s1 -> s0 == s1 /\ p s1)
=
NMSTATETOT?.reflect (fun (_, n) -> M.recall state rel p w, n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Witnessed.Core.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.NMSTTotal.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Witnessed.Core",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | _: Prims.unit -> FStar.NMSTTotal.NMSTATETOT Prims.bool | FStar.NMSTTotal.NMSTATETOT | [] | [] | [
"FStar.Preorder.preorder",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"FStar.NMSTTotal.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"Prims.op_Addition",
"Prims.l_True",
"Prims.eq2"
] | [] | false | true | false | false | false | let sample (#state: Type u#2) (#rel: P.preorder state) ()
: NMSTATETOT bool state rel (fun _ -> True) (fun s0 _ s1 -> s0 == s1) =
| NMSTATETOT?.reflect (fun (t, n) -> t n, n + 1) | false |
FStar.NMSTTotal.fst | FStar.NMSTTotal.put | val put (#state: Type u#2) (#rel: P.preorder state) (s: state)
: NMSTATETOT unit state rel (fun s0 -> rel s0 s) (fun _ _ s1 -> s1 == s) | val put (#state: Type u#2) (#rel: P.preorder state) (s: state)
: NMSTATETOT unit state rel (fun s0 -> rel s0 s) (fun _ _ s1 -> s1 == s) | let put (#state:Type u#2) (#rel:P.preorder state) (s:state)
: NMSTATETOT unit state rel
(fun s0 -> rel s0 s)
(fun _ _ s1 -> s1 == s)
=
NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.put s, n) | {
"file_name": "ulib/experimental/FStar.NMSTTotal.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 55,
"end_line": 123,
"start_col": 0,
"start_line": 118
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.NMSTTotal
module W = FStar.Witnessed.Core
module P = FStar.Preorder
module M = FStar.MSTTotal
open FStar.Monotonic.Pure
type tape = nat -> bool
type repr
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
=
(tape & nat) ->
M.MSTATETOT (a & nat) state rel req (fun s0 (x, _) s1 -> ens s0 x s1)
let return (a:Type) (x:a) (state:Type u#2) (rel:P.preorder state)
: repr a state rel (fun _ -> True) (fun s0 r s1 -> r == x /\ s0 == s1)
=
fun (_, n) -> x, n
let bind
(a:Type)
(b:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:a -> M.pre_t state)
(ens_g:a -> M.post_t state b)
(f:repr a state rel req_f ens_f)
(g:(x:a -> repr b state rel (req_g x) (ens_g x)))
: repr b state rel
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2))
=
fun (t, n) ->
let x, n1 = f (t, n) in
(g x) (t, n1)
let subcomp
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:M.pre_t state)
(ens_g:M.post_t state a)
(f:repr a state rel req_f ens_f)
: Pure (repr a state rel req_g ens_g)
(requires
(forall s. req_g s ==> req_f s) /\
(forall s0 x s1. (req_g s0 /\ ens_f s0 x s1) ==> ens_g s0 x s1))
(ensures fun _ -> True)
=
f
let if_then_else
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_then:M.pre_t state)
(ens_then:M.post_t state a)
(req_else:M.pre_t state)
(ens_else:M.post_t state a)
(f:repr a state rel req_then ens_then)
(g:repr a state rel req_else ens_else)
(p:bool)
: Type
=
repr a state rel
(fun s0 -> (p ==> req_then s0) /\ ((~ p) ==> req_else s0))
(fun s0 x s1 -> (p ==> ens_then s0 x s1) /\ ((~ p) ==> ens_else s0 x s1))
[@@ primitive_extraction]
total
reflectable
effect {
NMSTATETOT (a:Type)
([@@@ effect_param] state:Type u#2)
([@@@ effect_param] rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
with { repr; return; bind; subcomp; if_then_else }
}
[@@ noextract_to "krml"]
let get (#state:Type u#2) (#rel:P.preorder state) ()
: NMSTATETOT state state rel
(fun _ -> True)
(fun s0 s s1 -> s0 == s /\ s == s1)
=
NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.get (), n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Witnessed.Core.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.NMSTTotal.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Witnessed.Core",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: state -> FStar.NMSTTotal.NMSTATETOT Prims.unit | FStar.NMSTTotal.NMSTATETOT | [] | [] | [
"FStar.Preorder.preorder",
"FStar.Pervasives.Native.tuple2",
"FStar.NMSTTotal.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"FStar.MSTTotal.put",
"Prims.eq2"
] | [] | false | true | false | false | false | let put (#state: Type u#2) (#rel: P.preorder state) (s: state)
: NMSTATETOT unit state rel (fun s0 -> rel s0 s) (fun _ _ s1 -> s1 == s) =
| NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.put s, n) | false |
FStar.NMSTTotal.fst | FStar.NMSTTotal.witness | val witness (state: Type u#2) (rel: P.preorder state) (p: W.s_predicate state)
: NMSTATETOT (W.witnessed state rel p)
state
rel
(fun s0 -> p s0 /\ W.stable state rel p)
(fun s0 _ s1 -> s0 == s1) | val witness (state: Type u#2) (rel: P.preorder state) (p: W.s_predicate state)
: NMSTATETOT (W.witnessed state rel p)
state
rel
(fun s0 -> p s0 /\ W.stable state rel p)
(fun s0 _ s1 -> s0 == s1) | let witness (state:Type u#2) (rel:P.preorder state) (p:W.s_predicate state)
: NMSTATETOT (W.witnessed state rel p) state rel
(fun s0 -> p s0 /\ W.stable state rel p)
(fun s0 _ s1 -> s0 == s1)
=
NMSTATETOT?.reflect (fun (_, n) -> M.witness state rel p, n) | {
"file_name": "ulib/experimental/FStar.NMSTTotal.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 62,
"end_line": 132,
"start_col": 0,
"start_line": 127
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.NMSTTotal
module W = FStar.Witnessed.Core
module P = FStar.Preorder
module M = FStar.MSTTotal
open FStar.Monotonic.Pure
type tape = nat -> bool
type repr
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
=
(tape & nat) ->
M.MSTATETOT (a & nat) state rel req (fun s0 (x, _) s1 -> ens s0 x s1)
let return (a:Type) (x:a) (state:Type u#2) (rel:P.preorder state)
: repr a state rel (fun _ -> True) (fun s0 r s1 -> r == x /\ s0 == s1)
=
fun (_, n) -> x, n
let bind
(a:Type)
(b:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:a -> M.pre_t state)
(ens_g:a -> M.post_t state b)
(f:repr a state rel req_f ens_f)
(g:(x:a -> repr b state rel (req_g x) (ens_g x)))
: repr b state rel
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2))
=
fun (t, n) ->
let x, n1 = f (t, n) in
(g x) (t, n1)
let subcomp
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:M.pre_t state)
(ens_g:M.post_t state a)
(f:repr a state rel req_f ens_f)
: Pure (repr a state rel req_g ens_g)
(requires
(forall s. req_g s ==> req_f s) /\
(forall s0 x s1. (req_g s0 /\ ens_f s0 x s1) ==> ens_g s0 x s1))
(ensures fun _ -> True)
=
f
let if_then_else
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_then:M.pre_t state)
(ens_then:M.post_t state a)
(req_else:M.pre_t state)
(ens_else:M.post_t state a)
(f:repr a state rel req_then ens_then)
(g:repr a state rel req_else ens_else)
(p:bool)
: Type
=
repr a state rel
(fun s0 -> (p ==> req_then s0) /\ ((~ p) ==> req_else s0))
(fun s0 x s1 -> (p ==> ens_then s0 x s1) /\ ((~ p) ==> ens_else s0 x s1))
[@@ primitive_extraction]
total
reflectable
effect {
NMSTATETOT (a:Type)
([@@@ effect_param] state:Type u#2)
([@@@ effect_param] rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
with { repr; return; bind; subcomp; if_then_else }
}
[@@ noextract_to "krml"]
let get (#state:Type u#2) (#rel:P.preorder state) ()
: NMSTATETOT state state rel
(fun _ -> True)
(fun s0 s s1 -> s0 == s /\ s == s1)
=
NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.get (), n)
[@@ noextract_to "krml"]
let put (#state:Type u#2) (#rel:P.preorder state) (s:state)
: NMSTATETOT unit state rel
(fun s0 -> rel s0 s)
(fun _ _ s1 -> s1 == s)
=
NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.put s, n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Witnessed.Core.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.NMSTTotal.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Witnessed.Core",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | state: Type -> rel: FStar.Preorder.preorder state -> p: FStar.Witnessed.Core.s_predicate state
-> FStar.NMSTTotal.NMSTATETOT (FStar.Witnessed.Core.witnessed state rel p) | FStar.NMSTTotal.NMSTATETOT | [] | [] | [
"FStar.Preorder.preorder",
"FStar.Witnessed.Core.s_predicate",
"FStar.Pervasives.Native.tuple2",
"FStar.NMSTTotal.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Witnessed.Core.witnessed",
"FStar.MSTTotal.witness",
"Prims.l_and",
"FStar.Witnessed.Core.stable",
"Prims.eq2"
] | [] | false | true | false | false | false | let witness (state: Type u#2) (rel: P.preorder state) (p: W.s_predicate state)
: NMSTATETOT (W.witnessed state rel p)
state
rel
(fun s0 -> p s0 /\ W.stable state rel p)
(fun s0 _ s1 -> s0 == s1) =
| NMSTATETOT?.reflect (fun (_, n) -> M.witness state rel p, n) | false |
Hacl.K256.Field.fsti | Hacl.K256.Field.feval | val feval (h: mem) (e: felem) : GTot S.felem | val feval (h: mem) (e: felem) : GTot S.felem | let feval (h:mem) (e:felem) : GTot S.felem = as_nat h e % S.prime | {
"file_name": "code/k256/Hacl.K256.Field.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 65,
"end_line": 39,
"start_col": 0,
"start_line": 39
} | module Hacl.K256.Field
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 BSeq = Lib.ByteSequence
module S = Spec.K256
include Hacl.Spec.K256.Field52.Definitions
module BI = Hacl.Spec.K256.Field52
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** Specialized bignum library with a radix-2^{52} *)
inline_for_extraction noextract
let nlimb = 5ul
inline_for_extraction noextract
let felem = lbuffer uint64 nlimb
noextract
let as_felem5 (h:mem) (e:felem) : GTot felem5 =
let open Lib.Sequence in
let s = as_seq h e in
(s.[0], s.[1], s.[2], s.[3], s.[4])
noextract
let as_nat (h:mem) (e:felem) : GTot nat =
as_nat5 (as_felem5 h e) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Spec.K256.Field52.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.K256.Field.fsti"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52",
"short_module": "BI"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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"
} | false | h: FStar.Monotonic.HyperStack.mem -> e: Hacl.K256.Field.felem -> Prims.GTot Spec.K256.PointOps.felem | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Hacl.K256.Field.felem",
"Prims.op_Modulus",
"Hacl.K256.Field.as_nat",
"Spec.K256.PointOps.prime",
"Spec.K256.PointOps.felem"
] | [] | false | false | false | false | false | let feval (h: mem) (e: felem) : GTot S.felem =
| as_nat h e % S.prime | false |
FStar.NMSTTotal.fst | FStar.NMSTTotal.nmst_tot_assert | val nmst_tot_assert (#state: Type u#2) (#rel: P.preorder state) (p: Type)
: NMSTATETOT unit state rel (fun _ -> p) (fun m0 _ m1 -> p /\ m0 == m1) | val nmst_tot_assert (#state: Type u#2) (#rel: P.preorder state) (p: Type)
: NMSTATETOT unit state rel (fun _ -> p) (fun m0 _ m1 -> p /\ m0 == m1) | let nmst_tot_assert (#state:Type u#2) (#rel:P.preorder state) (p:Type)
: NMSTATETOT unit state rel (fun _ -> p) (fun m0 _ m1 -> p /\ m0 == m1)
=
assert p | {
"file_name": "ulib/experimental/FStar.NMSTTotal.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 10,
"end_line": 183,
"start_col": 0,
"start_line": 180
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.NMSTTotal
module W = FStar.Witnessed.Core
module P = FStar.Preorder
module M = FStar.MSTTotal
open FStar.Monotonic.Pure
type tape = nat -> bool
type repr
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
=
(tape & nat) ->
M.MSTATETOT (a & nat) state rel req (fun s0 (x, _) s1 -> ens s0 x s1)
let return (a:Type) (x:a) (state:Type u#2) (rel:P.preorder state)
: repr a state rel (fun _ -> True) (fun s0 r s1 -> r == x /\ s0 == s1)
=
fun (_, n) -> x, n
let bind
(a:Type)
(b:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:a -> M.pre_t state)
(ens_g:a -> M.post_t state b)
(f:repr a state rel req_f ens_f)
(g:(x:a -> repr b state rel (req_g x) (ens_g x)))
: repr b state rel
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2))
=
fun (t, n) ->
let x, n1 = f (t, n) in
(g x) (t, n1)
let subcomp
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:M.pre_t state)
(ens_g:M.post_t state a)
(f:repr a state rel req_f ens_f)
: Pure (repr a state rel req_g ens_g)
(requires
(forall s. req_g s ==> req_f s) /\
(forall s0 x s1. (req_g s0 /\ ens_f s0 x s1) ==> ens_g s0 x s1))
(ensures fun _ -> True)
=
f
let if_then_else
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_then:M.pre_t state)
(ens_then:M.post_t state a)
(req_else:M.pre_t state)
(ens_else:M.post_t state a)
(f:repr a state rel req_then ens_then)
(g:repr a state rel req_else ens_else)
(p:bool)
: Type
=
repr a state rel
(fun s0 -> (p ==> req_then s0) /\ ((~ p) ==> req_else s0))
(fun s0 x s1 -> (p ==> ens_then s0 x s1) /\ ((~ p) ==> ens_else s0 x s1))
[@@ primitive_extraction]
total
reflectable
effect {
NMSTATETOT (a:Type)
([@@@ effect_param] state:Type u#2)
([@@@ effect_param] rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
with { repr; return; bind; subcomp; if_then_else }
}
[@@ noextract_to "krml"]
let get (#state:Type u#2) (#rel:P.preorder state) ()
: NMSTATETOT state state rel
(fun _ -> True)
(fun s0 s s1 -> s0 == s /\ s == s1)
=
NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.get (), n)
[@@ noextract_to "krml"]
let put (#state:Type u#2) (#rel:P.preorder state) (s:state)
: NMSTATETOT unit state rel
(fun s0 -> rel s0 s)
(fun _ _ s1 -> s1 == s)
=
NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.put s, n)
[@@ noextract_to "krml"]
let witness (state:Type u#2) (rel:P.preorder state) (p:W.s_predicate state)
: NMSTATETOT (W.witnessed state rel p) state rel
(fun s0 -> p s0 /\ W.stable state rel p)
(fun s0 _ s1 -> s0 == s1)
=
NMSTATETOT?.reflect (fun (_, n) -> M.witness state rel p, n)
[@@ noextract_to "krml"]
let recall (state:Type u#2)
(rel:P.preorder state)
(p:W.s_predicate state)
(w:W.witnessed state rel p)
: NMSTATETOT unit state rel
(fun _ -> True)
(fun s0 _ s1 -> s0 == s1 /\ p s1)
=
NMSTATETOT?.reflect (fun (_, n) -> M.recall state rel p w, n)
[@@ noextract_to "krml"]
let sample (#state:Type u#2) (#rel:P.preorder state) ()
: NMSTATETOT bool state rel
(fun _ -> True)
(fun s0 _ s1 -> s0 == s1)
=
NMSTATETOT?.reflect (fun (t, n) -> t n, n+1)
let lift_pure_nmst
(a:Type)
(wp:pure_wp a)
(state:Type u#2)
(rel:P.preorder state)
(f:eqtype_as_type unit -> PURE a wp)
: repr a state rel
(fun s0 -> wp (fun _ -> True))
(fun s0 x s1 -> wp (fun _ -> True) /\ (~ (wp (fun r -> r =!= x \/ s0 =!= s1))))
=
fun (_, n) ->
elim_pure_wp_monotonicity wp;
let x = f () in
x, n
sub_effect PURE ~> NMSTATETOT = lift_pure_nmst
let nmst_tot_assume (#state:Type u#2) (#rel:P.preorder state) (p:Type)
: NMSTATETOT unit state rel (fun _ -> True) (fun m0 _ m1 -> p /\ m0 == m1)
=
assume p
let nmst_tot_admit (#state:Type u#2) (#rel:P.preorder state) (#a:Type) ()
: NMSTATETOT a state rel (fun _ -> True) (fun _ _ _ -> False)
=
admit () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Witnessed.Core.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.NMSTTotal.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Witnessed.Core",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | p: Type0 -> FStar.NMSTTotal.NMSTATETOT Prims.unit | FStar.NMSTTotal.NMSTATETOT | [] | [] | [
"FStar.Preorder.preorder",
"Prims._assert",
"Prims.unit",
"Prims.l_and",
"Prims.eq2"
] | [] | false | true | false | false | false | let nmst_tot_assert (#state: Type u#2) (#rel: P.preorder state) (p: Type)
: NMSTATETOT unit state rel (fun _ -> p) (fun m0 _ m1 -> p /\ m0 == m1) =
| assert p | false |
Hacl.K256.Field.fsti | Hacl.K256.Field.as_felem5 | val as_felem5 (h: mem) (e: felem) : GTot felem5 | val as_felem5 (h: mem) (e: felem) : GTot felem5 | let as_felem5 (h:mem) (e:felem) : GTot felem5 =
let open Lib.Sequence in
let s = as_seq h e in
(s.[0], s.[1], s.[2], s.[3], s.[4]) | {
"file_name": "code/k256/Hacl.K256.Field.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 37,
"end_line": 32,
"start_col": 0,
"start_line": 29
} | module Hacl.K256.Field
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 BSeq = Lib.ByteSequence
module S = Spec.K256
include Hacl.Spec.K256.Field52.Definitions
module BI = Hacl.Spec.K256.Field52
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** Specialized bignum library with a radix-2^{52} *)
inline_for_extraction noextract
let nlimb = 5ul
inline_for_extraction noextract
let felem = lbuffer uint64 nlimb | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Spec.K256.Field52.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.K256.Field.fsti"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52",
"short_module": "BI"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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"
} | false | h: FStar.Monotonic.HyperStack.mem -> e: Hacl.K256.Field.felem
-> Prims.GTot Hacl.Spec.K256.Field52.Definitions.felem5 | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Hacl.K256.Field.felem",
"FStar.Pervasives.Native.Mktuple5",
"Lib.IntTypes.uint64",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.K256.Field.nlimb",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Spec.K256.Field52.Definitions.felem5"
] | [] | false | false | false | false | false | let as_felem5 (h: mem) (e: felem) : GTot felem5 =
| let open Lib.Sequence in
let s = as_seq h e in
(s.[ 0 ], s.[ 1 ], s.[ 2 ], s.[ 3 ], s.[ 4 ]) | false |
FStar.NMSTTotal.fst | FStar.NMSTTotal.lift_pure_nmst | val lift_pure_nmst
(a: Type)
(wp: pure_wp a)
(state: Type u#2)
(rel: P.preorder state)
(f: (eqtype_as_type unit -> PURE a wp))
: repr a
state
rel
(fun s0 -> wp (fun _ -> True))
(fun s0 x s1 -> wp (fun _ -> True) /\ (~(wp (fun r -> r =!= x \/ s0 =!= s1)))) | val lift_pure_nmst
(a: Type)
(wp: pure_wp a)
(state: Type u#2)
(rel: P.preorder state)
(f: (eqtype_as_type unit -> PURE a wp))
: repr a
state
rel
(fun s0 -> wp (fun _ -> True))
(fun s0 x s1 -> wp (fun _ -> True) /\ (~(wp (fun r -> r =!= x \/ s0 =!= s1)))) | let lift_pure_nmst
(a:Type)
(wp:pure_wp a)
(state:Type u#2)
(rel:P.preorder state)
(f:eqtype_as_type unit -> PURE a wp)
: repr a state rel
(fun s0 -> wp (fun _ -> True))
(fun s0 x s1 -> wp (fun _ -> True) /\ (~ (wp (fun r -> r =!= x \/ s0 =!= s1))))
=
fun (_, n) ->
elim_pure_wp_monotonicity wp;
let x = f () in
x, n | {
"file_name": "ulib/experimental/FStar.NMSTTotal.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 8,
"end_line": 166,
"start_col": 0,
"start_line": 153
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.NMSTTotal
module W = FStar.Witnessed.Core
module P = FStar.Preorder
module M = FStar.MSTTotal
open FStar.Monotonic.Pure
type tape = nat -> bool
type repr
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
=
(tape & nat) ->
M.MSTATETOT (a & nat) state rel req (fun s0 (x, _) s1 -> ens s0 x s1)
let return (a:Type) (x:a) (state:Type u#2) (rel:P.preorder state)
: repr a state rel (fun _ -> True) (fun s0 r s1 -> r == x /\ s0 == s1)
=
fun (_, n) -> x, n
let bind
(a:Type)
(b:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:a -> M.pre_t state)
(ens_g:a -> M.post_t state b)
(f:repr a state rel req_f ens_f)
(g:(x:a -> repr b state rel (req_g x) (ens_g x)))
: repr b state rel
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2))
=
fun (t, n) ->
let x, n1 = f (t, n) in
(g x) (t, n1)
let subcomp
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:M.pre_t state)
(ens_g:M.post_t state a)
(f:repr a state rel req_f ens_f)
: Pure (repr a state rel req_g ens_g)
(requires
(forall s. req_g s ==> req_f s) /\
(forall s0 x s1. (req_g s0 /\ ens_f s0 x s1) ==> ens_g s0 x s1))
(ensures fun _ -> True)
=
f
let if_then_else
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_then:M.pre_t state)
(ens_then:M.post_t state a)
(req_else:M.pre_t state)
(ens_else:M.post_t state a)
(f:repr a state rel req_then ens_then)
(g:repr a state rel req_else ens_else)
(p:bool)
: Type
=
repr a state rel
(fun s0 -> (p ==> req_then s0) /\ ((~ p) ==> req_else s0))
(fun s0 x s1 -> (p ==> ens_then s0 x s1) /\ ((~ p) ==> ens_else s0 x s1))
[@@ primitive_extraction]
total
reflectable
effect {
NMSTATETOT (a:Type)
([@@@ effect_param] state:Type u#2)
([@@@ effect_param] rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
with { repr; return; bind; subcomp; if_then_else }
}
[@@ noextract_to "krml"]
let get (#state:Type u#2) (#rel:P.preorder state) ()
: NMSTATETOT state state rel
(fun _ -> True)
(fun s0 s s1 -> s0 == s /\ s == s1)
=
NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.get (), n)
[@@ noextract_to "krml"]
let put (#state:Type u#2) (#rel:P.preorder state) (s:state)
: NMSTATETOT unit state rel
(fun s0 -> rel s0 s)
(fun _ _ s1 -> s1 == s)
=
NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.put s, n)
[@@ noextract_to "krml"]
let witness (state:Type u#2) (rel:P.preorder state) (p:W.s_predicate state)
: NMSTATETOT (W.witnessed state rel p) state rel
(fun s0 -> p s0 /\ W.stable state rel p)
(fun s0 _ s1 -> s0 == s1)
=
NMSTATETOT?.reflect (fun (_, n) -> M.witness state rel p, n)
[@@ noextract_to "krml"]
let recall (state:Type u#2)
(rel:P.preorder state)
(p:W.s_predicate state)
(w:W.witnessed state rel p)
: NMSTATETOT unit state rel
(fun _ -> True)
(fun s0 _ s1 -> s0 == s1 /\ p s1)
=
NMSTATETOT?.reflect (fun (_, n) -> M.recall state rel p w, n)
[@@ noextract_to "krml"]
let sample (#state:Type u#2) (#rel:P.preorder state) ()
: NMSTATETOT bool state rel
(fun _ -> True)
(fun s0 _ s1 -> s0 == s1)
=
NMSTATETOT?.reflect (fun (t, n) -> t n, n+1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Witnessed.Core.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.NMSTTotal.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Witnessed.Core",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
a: Type ->
wp: Prims.pure_wp a ->
state: Type ->
rel: FStar.Preorder.preorder state ->
f: (_: FStar.Pervasives.eqtype_as_type Prims.unit -> Prims.PURE a)
-> FStar.NMSTTotal.repr a
state
rel
(fun _ -> wp (fun _ -> Prims.l_True))
(fun s0 x s1 -> wp (fun _ -> Prims.l_True) /\ ~(wp (fun r -> ~(r == x) \/ ~(s0 == s1)))) | Prims.Tot | [
"total"
] | [] | [
"Prims.pure_wp",
"FStar.Preorder.preorder",
"FStar.Pervasives.eqtype_as_type",
"Prims.unit",
"FStar.Pervasives.Native.tuple2",
"FStar.NMSTTotal.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Monotonic.Pure.elim_pure_wp_monotonicity",
"FStar.NMSTTotal.repr",
"Prims.l_True",
"Prims.l_and",
"Prims.l_not",
"Prims.l_or",
"Prims.eq2"
] | [] | false | false | false | false | false | let lift_pure_nmst
(a: Type)
(wp: pure_wp a)
(state: Type u#2)
(rel: P.preorder state)
(f: (eqtype_as_type unit -> PURE a wp))
: repr a
state
rel
(fun s0 -> wp (fun _ -> True))
(fun s0 x s1 -> wp (fun _ -> True) /\ (~(wp (fun r -> r =!= x \/ s0 =!= s1)))) =
| fun (_, n) ->
elim_pure_wp_monotonicity wp;
let x = f () in
x, n | false |
Pulse.Checker.Prover.Base.fst | Pulse.Checker.Prover.Base.list_as_vprop' | val list_as_vprop' (vp: vprop) (fvps: list vprop) : Tot vprop (decreases fvps) | val list_as_vprop' (vp: vprop) (fvps: list vprop) : Tot vprop (decreases fvps) | let rec list_as_vprop' (vp:vprop) (fvps:list vprop)
: Tot vprop (decreases fvps) =
match fvps with
| [] -> vp
| hd::tl -> list_as_vprop' (tm_star vp hd) tl | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Base.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 47,
"end_line": 31,
"start_col": 0,
"start_line": 27
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Base
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Typing.Combinators
module RU = Pulse.RuntimeUtils
module T = FStar.Tactics.V2
module PS = Pulse.Checker.Prover.Substs | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Base.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | vp: Pulse.Syntax.Base.vprop -> fvps: Prims.list Pulse.Syntax.Base.vprop
-> Prims.Tot Pulse.Syntax.Base.vprop | Prims.Tot | [
"total",
""
] | [] | [
"Pulse.Syntax.Base.vprop",
"Prims.list",
"Pulse.Checker.Prover.Base.list_as_vprop'",
"Pulse.Syntax.Base.tm_star"
] | [
"recursion"
] | false | false | false | true | false | let rec list_as_vprop' (vp: vprop) (fvps: list vprop) : Tot vprop (decreases fvps) =
| match fvps with
| [] -> vp
| hd :: tl -> list_as_vprop' (tm_star vp hd) tl | false |
FStar.NMSTTotal.fst | FStar.NMSTTotal.recall | val recall
(state: Type u#2)
(rel: P.preorder state)
(p: W.s_predicate state)
(w: W.witnessed state rel p)
: NMSTATETOT unit state rel (fun _ -> True) (fun s0 _ s1 -> s0 == s1 /\ p s1) | val recall
(state: Type u#2)
(rel: P.preorder state)
(p: W.s_predicate state)
(w: W.witnessed state rel p)
: NMSTATETOT unit state rel (fun _ -> True) (fun s0 _ s1 -> s0 == s1 /\ p s1) | let recall (state:Type u#2)
(rel:P.preorder state)
(p:W.s_predicate state)
(w:W.witnessed state rel p)
: NMSTATETOT unit state rel
(fun _ -> True)
(fun s0 _ s1 -> s0 == s1 /\ p s1)
=
NMSTATETOT?.reflect (fun (_, n) -> M.recall state rel p w, n) | {
"file_name": "ulib/experimental/FStar.NMSTTotal.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 63,
"end_line": 143,
"start_col": 0,
"start_line": 135
} | (*
Copyright 2020 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.NMSTTotal
module W = FStar.Witnessed.Core
module P = FStar.Preorder
module M = FStar.MSTTotal
open FStar.Monotonic.Pure
type tape = nat -> bool
type repr
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
=
(tape & nat) ->
M.MSTATETOT (a & nat) state rel req (fun s0 (x, _) s1 -> ens s0 x s1)
let return (a:Type) (x:a) (state:Type u#2) (rel:P.preorder state)
: repr a state rel (fun _ -> True) (fun s0 r s1 -> r == x /\ s0 == s1)
=
fun (_, n) -> x, n
let bind
(a:Type)
(b:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:a -> M.pre_t state)
(ens_g:a -> M.post_t state b)
(f:repr a state rel req_f ens_f)
(g:(x:a -> repr b state rel (req_g x) (ens_g x)))
: repr b state rel
(fun s0 -> req_f s0 /\ (forall x s1. ens_f s0 x s1 ==> (req_g x) s1))
(fun s0 r s2 -> req_f s0 /\ (exists x s1. ens_f s0 x s1 /\ (req_g x) s1 /\ (ens_g x) s1 r s2))
=
fun (t, n) ->
let x, n1 = f (t, n) in
(g x) (t, n1)
let subcomp
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_f:M.pre_t state)
(ens_f:M.post_t state a)
(req_g:M.pre_t state)
(ens_g:M.post_t state a)
(f:repr a state rel req_f ens_f)
: Pure (repr a state rel req_g ens_g)
(requires
(forall s. req_g s ==> req_f s) /\
(forall s0 x s1. (req_g s0 /\ ens_f s0 x s1) ==> ens_g s0 x s1))
(ensures fun _ -> True)
=
f
let if_then_else
(a:Type)
(state:Type u#2)
(rel:P.preorder state)
(req_then:M.pre_t state)
(ens_then:M.post_t state a)
(req_else:M.pre_t state)
(ens_else:M.post_t state a)
(f:repr a state rel req_then ens_then)
(g:repr a state rel req_else ens_else)
(p:bool)
: Type
=
repr a state rel
(fun s0 -> (p ==> req_then s0) /\ ((~ p) ==> req_else s0))
(fun s0 x s1 -> (p ==> ens_then s0 x s1) /\ ((~ p) ==> ens_else s0 x s1))
[@@ primitive_extraction]
total
reflectable
effect {
NMSTATETOT (a:Type)
([@@@ effect_param] state:Type u#2)
([@@@ effect_param] rel:P.preorder state)
(req:M.pre_t state)
(ens:M.post_t state a)
with { repr; return; bind; subcomp; if_then_else }
}
[@@ noextract_to "krml"]
let get (#state:Type u#2) (#rel:P.preorder state) ()
: NMSTATETOT state state rel
(fun _ -> True)
(fun s0 s s1 -> s0 == s /\ s == s1)
=
NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.get (), n)
[@@ noextract_to "krml"]
let put (#state:Type u#2) (#rel:P.preorder state) (s:state)
: NMSTATETOT unit state rel
(fun s0 -> rel s0 s)
(fun _ _ s1 -> s1 == s)
=
NMSTATETOT?.reflect (fun (_, n) -> MSTTotal.put s, n)
[@@ noextract_to "krml"]
let witness (state:Type u#2) (rel:P.preorder state) (p:W.s_predicate state)
: NMSTATETOT (W.witnessed state rel p) state rel
(fun s0 -> p s0 /\ W.stable state rel p)
(fun s0 _ s1 -> s0 == s1)
=
NMSTATETOT?.reflect (fun (_, n) -> M.witness state rel p, n) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.Witnessed.Core.fsti.checked",
"FStar.Preorder.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.MSTTotal.fst.checked",
"FStar.Monotonic.Pure.fst.checked"
],
"interface_file": false,
"source_file": "FStar.NMSTTotal.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Monotonic.Pure",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.MSTTotal",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "FStar.Preorder",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "FStar.Witnessed.Core",
"short_module": "W"
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
state: Type ->
rel: FStar.Preorder.preorder state ->
p: FStar.Witnessed.Core.s_predicate state ->
w: FStar.Witnessed.Core.witnessed state rel p
-> FStar.NMSTTotal.NMSTATETOT Prims.unit | FStar.NMSTTotal.NMSTATETOT | [] | [] | [
"FStar.Preorder.preorder",
"FStar.Witnessed.Core.s_predicate",
"FStar.Witnessed.Core.witnessed",
"FStar.Pervasives.Native.tuple2",
"FStar.NMSTTotal.tape",
"Prims.nat",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"FStar.MSTTotal.recall",
"Prims.l_True",
"Prims.l_and",
"Prims.eq2"
] | [] | false | true | false | false | false | let recall
(state: Type u#2)
(rel: P.preorder state)
(p: W.s_predicate state)
(w: W.witnessed state rel p)
: NMSTATETOT unit state rel (fun _ -> True) (fun s0 _ s1 -> s0 == s1 /\ p s1) =
| NMSTATETOT?.reflect (fun (_, n) -> M.recall state rel p w, n) | false |
Hacl.Impl.Poly1305.Bignum128.fst | Hacl.Impl.Poly1305.Bignum128.mod_add128 | val mod_add128:
a:(uint64 & uint64)
-> b:(uint64 & uint64) ->
Pure (uint64 & uint64)
(requires True)
(ensures (fun (r0, r1) ->
let (a0, a1) = a in let (b0, b1) = b in
v r1 * pow2 64 + v r0 == ((v a1 + v b1) * pow2 64 + v a0 + v b0) % pow2 128)) | val mod_add128:
a:(uint64 & uint64)
-> b:(uint64 & uint64) ->
Pure (uint64 & uint64)
(requires True)
(ensures (fun (r0, r1) ->
let (a0, a1) = a in let (b0, b1) = b in
v r1 * pow2 64 + v r0 == ((v a1 + v b1) * pow2 64 + v a0 + v b0) % pow2 128)) | let mod_add128 (a0, a1) (b0, b1) =
mod_add128_lemma (a0, a1) (b0, b1);
let r0 = a0 +. b0 in
let r1 = a1 +. b1 in
let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
let r1 = r1 +. c in
(r0, r1) | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Bignum128.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 123,
"start_col": 0,
"start_line": 117
} | module Hacl.Impl.Poly1305.Bignum128
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Poly1305.Lemmas
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
friend FStar.UInt128
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let uints64_from_bytes_le b =
let h0 = ST.get () in
let lo = uint_from_bytes_le #U64 (sub b 0ul 8ul) in
let hi = uint_from_bytes_le #U64 (sub b 8ul 8ul) in
uint_from_bytes_le_lemma (as_seq h0 b);
lo, hi
let uints64_to_bytes_le b r0 r1 =
let h0 = ST.get () in
update_sub_f h0 b 0ul 8ul
(fun h -> BSeq.uint_to_bytes_le #U64 r0)
(fun _ -> uint_to_bytes_le (sub b 0ul 8ul) r0);
let h1 = ST.get () in
update_sub_f h1 b 8ul 8ul
(fun h -> BSeq.uint_to_bytes_le #U64 r1)
(fun _ -> uint_to_bytes_le (sub b 8ul 8ul) r1);
//uint_to_bytes_le (sub b 0ul 8ul) r0;
//uint_to_bytes_le (sub b 8ul 8ul) r1;
let h2 = ST.get () in
uints64_to_bytes_le_lemma r0 r1;
LSeq.eq_intro (LSeq.sub (as_seq h2 b) 0 8) (BSeq.uint_to_bytes_le #U64 r0);
LSeq.lemma_concat2
8 (BSeq.uint_to_bytes_le #U64 r0)
8 (BSeq.uint_to_bytes_le #U64 r1) (as_seq h2 b)
val constant_time_carry_ok: r0:uint64 -> b0:uint64 ->
Lemma (let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
v c == (if v r0 < v b0 then 1 else 0))
let constant_time_carry_ok r0 b0 =
let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
let r0' = Lib.RawIntTypes.u64_to_UInt64 r0 in
let b0' = Lib.RawIntTypes.u64_to_UInt64 b0 in
let c' = FStar.UInt128.constant_time_carry r0' b0' in
logxor_spec r0 b0;
logxor_spec (r0 -. b0) b0;
logor_spec (r0 ^. b0) ((r0 -. b0) ^. b0);
logxor_spec r0 ((r0 ^. b0) |. ((r0 -. b0) ^. b0));
assert (v c' == v c);
FStar.UInt128.constant_time_carry_ok r0' b0'
val add_mod_small: a:nat -> b:nat -> n:pos -> Lemma
(requires a % n + b % n < n)
(ensures a % n + b % n == (a + b) % n)
let add_mod_small a b n =
FStar.Math.Lemmas.modulo_lemma (a % n + b % n) n;
assert (a % n + b % n == (a % n + b % n) % n);
FStar.Math.Lemmas.lemma_mod_plus_distr_l a (b % n) n;
FStar.Math.Lemmas.lemma_mod_plus_distr_r a b n
val mod_add128_lemma: a:(uint64 & uint64) -> b:(uint64 & uint64) ->
Lemma (let (a0, a1) = a in let (b0, b1) = b in
let r0 = a0 +. b0 in let r1 = a1 +. b1 in
let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
let r1 = r1 +. c in
v r1 * pow2 64 + v r0 == ((v a1 + v b1) * pow2 64 + v a0 + v b0) % pow2 128)
let mod_add128_lemma a b =
let (a0, a1) = a in
let (b0, b1) = b in
let r0 = a0 +. b0 in
let r1 = a1 +. b1 in
let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
constant_time_carry_ok r0 b0;
assert (v c == (if v r0 < v b0 then 1 else 0));
assert (v c == (v a0 + v b0) / pow2 64);
let r2 = r1 +. c in
calc (==) {
v r2 * pow2 64 + v r0;
(==) { }
((v a1 + v b1) % pow2 64 + (v a0 + v b0) / pow2 64) % pow2 64 * pow2 64 + (v a0 + v b0) % pow2 64;
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 ((v a1 + v b1) % pow2 64 + (v a0 + v b0) / pow2 64) 128 64 }
((v a1 + v b1) % pow2 64 + (v a0 + v b0) / pow2 64) * pow2 64 % pow2 128 + (v a0 + v b0) % pow2 64;
(==) { }
((v a1 + v b1) % pow2 64 * pow2 64 + (v a0 + v b0) / pow2 64 * pow2 64) % pow2 128 + (v a0 + v b0) % pow2 64;
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v a1 + v b1) 128 64 }
((v a1 + v b1) * pow2 64 % pow2 128 + (v a0 + v b0) / pow2 64 * pow2 64) % pow2 128 + (v a0 + v b0) % pow2 64;
(==) { Math.Lemmas.lemma_mod_plus_distr_l ((v a1 + v b1) * pow2 64) ((v a0 + v b0) / pow2 64 * pow2 64) (pow2 128) }
((v a1 + v b1) * pow2 64 + (v a0 + v b0) / pow2 64 * pow2 64) % pow2 128 + (v a0 + v b0) % pow2 64;
(==) { Math.Lemmas.modulo_lemma ((v a0 + v b0) % pow2 64) (pow2 128) }
((v a1 + v b1) * pow2 64 + (v a0 + v b0) / pow2 64 * pow2 64) % pow2 128 + ((v a0 + v b0) % pow2 64) % pow2 128;
};
assert (v r2 * pow2 64 + v r0 ==
((v a1 + v b1) * pow2 64 + (v a0 + v b0) / pow2 64 * pow2 64) % pow2 128 + ((v a0 + v b0) % pow2 64) % pow2 128);
assert (v r2 * pow2 64 + v r0 < pow2 128);
add_mod_small ((v a1 + v b1) * pow2 64 + (v a0 + v b0) / pow2 64 * pow2 64) ((v a0 + v b0) % pow2 64) (pow2 128);
Math.Lemmas.euclidean_division_definition (v a0 + v b0) (pow2 64);
assert (v r2 * pow2 64 + v r0 == ((v a1 + v b1) * pow2 64 + v a0 + v b0) % pow2 128) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt128.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Poly1305.Bignum128.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: (Lib.IntTypes.uint64 * Lib.IntTypes.uint64) -> b: (Lib.IntTypes.uint64 * Lib.IntTypes.uint64)
-> Prims.Pure (Lib.IntTypes.uint64 * Lib.IntTypes.uint64) | Prims.Pure | [] | [] | [
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.uint64",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.op_Greater_Greater_Dot",
"Lib.IntTypes.op_Hat_Dot",
"Lib.IntTypes.op_Bar_Dot",
"Lib.IntTypes.op_Subtraction_Dot",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"Hacl.Impl.Poly1305.Bignum128.mod_add128_lemma"
] | [] | false | false | false | false | false | let mod_add128 (a0, a1) (b0, b1) =
| mod_add128_lemma (a0, a1) (b0, b1);
let r0 = a0 +. b0 in
let r1 = a1 +. b1 in
let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
let r1 = r1 +. c in
(r0, r1) | false |
Hacl.Impl.Poly1305.Bignum128.fst | Hacl.Impl.Poly1305.Bignum128.constant_time_carry_ok | val constant_time_carry_ok: r0:uint64 -> b0:uint64 ->
Lemma (let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
v c == (if v r0 < v b0 then 1 else 0)) | val constant_time_carry_ok: r0:uint64 -> b0:uint64 ->
Lemma (let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
v c == (if v r0 < v b0 then 1 else 0)) | let constant_time_carry_ok r0 b0 =
let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
let r0' = Lib.RawIntTypes.u64_to_UInt64 r0 in
let b0' = Lib.RawIntTypes.u64_to_UInt64 b0 in
let c' = FStar.UInt128.constant_time_carry r0' b0' in
logxor_spec r0 b0;
logxor_spec (r0 -. b0) b0;
logor_spec (r0 ^. b0) ((r0 -. b0) ^. b0);
logxor_spec r0 ((r0 ^. b0) |. ((r0 -. b0) ^. b0));
assert (v c' == v c);
FStar.UInt128.constant_time_carry_ok r0' b0' | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Bignum128.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 46,
"end_line": 62,
"start_col": 0,
"start_line": 52
} | module Hacl.Impl.Poly1305.Bignum128
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Poly1305.Lemmas
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
friend FStar.UInt128
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let uints64_from_bytes_le b =
let h0 = ST.get () in
let lo = uint_from_bytes_le #U64 (sub b 0ul 8ul) in
let hi = uint_from_bytes_le #U64 (sub b 8ul 8ul) in
uint_from_bytes_le_lemma (as_seq h0 b);
lo, hi
let uints64_to_bytes_le b r0 r1 =
let h0 = ST.get () in
update_sub_f h0 b 0ul 8ul
(fun h -> BSeq.uint_to_bytes_le #U64 r0)
(fun _ -> uint_to_bytes_le (sub b 0ul 8ul) r0);
let h1 = ST.get () in
update_sub_f h1 b 8ul 8ul
(fun h -> BSeq.uint_to_bytes_le #U64 r1)
(fun _ -> uint_to_bytes_le (sub b 8ul 8ul) r1);
//uint_to_bytes_le (sub b 0ul 8ul) r0;
//uint_to_bytes_le (sub b 8ul 8ul) r1;
let h2 = ST.get () in
uints64_to_bytes_le_lemma r0 r1;
LSeq.eq_intro (LSeq.sub (as_seq h2 b) 0 8) (BSeq.uint_to_bytes_le #U64 r0);
LSeq.lemma_concat2
8 (BSeq.uint_to_bytes_le #U64 r0)
8 (BSeq.uint_to_bytes_le #U64 r1) (as_seq h2 b)
val constant_time_carry_ok: r0:uint64 -> b0:uint64 ->
Lemma (let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
v c == (if v r0 < v b0 then 1 else 0)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt128.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Poly1305.Bignum128.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | r0: Lib.IntTypes.uint64 -> b0: Lib.IntTypes.uint64
-> FStar.Pervasives.Lemma
(ensures
(let c = r0 ^. (r0 ^. b0 |. r0 -. b0 ^. b0) >>. 63ul in
Lib.IntTypes.v c ==
(match Lib.IntTypes.v r0 < Lib.IntTypes.v b0 with
| true -> 1
| _ -> 0))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Lib.IntTypes.uint64",
"FStar.UInt128.constant_time_carry_ok",
"Prims.unit",
"Prims._assert",
"Prims.eq2",
"Lib.IntTypes.range_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.v",
"Lib.IntTypes.PUB",
"Lib.IntTypes.SEC",
"Lib.IntTypes.logxor_spec",
"Lib.IntTypes.op_Bar_Dot",
"Lib.IntTypes.op_Hat_Dot",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.logor_spec",
"FStar.UInt64.t",
"FStar.UInt128.constant_time_carry",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"Prims.l_or",
"Lib.IntTypes.range",
"FStar.UInt.size",
"FStar.UInt64.v",
"Lib.RawIntTypes.u64_to_UInt64",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Greater_Greater_Dot",
"FStar.UInt32.__uint_to_t"
] | [] | true | false | true | false | false | let constant_time_carry_ok r0 b0 =
| let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
let r0' = Lib.RawIntTypes.u64_to_UInt64 r0 in
let b0' = Lib.RawIntTypes.u64_to_UInt64 b0 in
let c' = FStar.UInt128.constant_time_carry r0' b0' in
logxor_spec r0 b0;
logxor_spec (r0 -. b0) b0;
logor_spec (r0 ^. b0) ((r0 -. b0) ^. b0);
logxor_spec r0 ((r0 ^. b0) |. ((r0 -. b0) ^. b0));
assert (v c' == v c);
FStar.UInt128.constant_time_carry_ok r0' b0' | false |
Hacl.Impl.Poly1305.Bignum128.fst | Hacl.Impl.Poly1305.Bignum128.uints64_from_bytes_le | val uints64_from_bytes_le: b:lbuffer uint8 16ul ->
Stack (uint64 & uint64)
(requires fun h -> live h b)
(ensures fun h0 (lo, hi) h1 -> h0 == h1 /\
v hi * pow2 64 + v lo == BSeq.nat_from_bytes_le (as_seq h0 b)) | val uints64_from_bytes_le: b:lbuffer uint8 16ul ->
Stack (uint64 & uint64)
(requires fun h -> live h b)
(ensures fun h0 (lo, hi) h1 -> h0 == h1 /\
v hi * pow2 64 + v lo == BSeq.nat_from_bytes_le (as_seq h0 b)) | let uints64_from_bytes_le b =
let h0 = ST.get () in
let lo = uint_from_bytes_le #U64 (sub b 0ul 8ul) in
let hi = uint_from_bytes_le #U64 (sub b 8ul 8ul) in
uint_from_bytes_le_lemma (as_seq h0 b);
lo, hi | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Bignum128.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 26,
"start_col": 0,
"start_line": 21
} | module Hacl.Impl.Poly1305.Bignum128
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Poly1305.Lemmas
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
friend FStar.UInt128
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt128.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Poly1305.Bignum128.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 16ul
-> FStar.HyperStack.ST.Stack (Lib.IntTypes.uint64 * Lib.IntTypes.uint64) | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.uint64",
"Prims.unit",
"Hacl.Impl.Poly1305.Lemmas.uint_from_bytes_le_lemma",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Lib.ByteBuffer.uint_from_bytes_le",
"Lib.IntTypes.uint_t",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.mk_int",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.sub",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | false | true | false | false | false | let uints64_from_bytes_le b =
| let h0 = ST.get () in
let lo = uint_from_bytes_le #U64 (sub b 0ul 8ul) in
let hi = uint_from_bytes_le #U64 (sub b 8ul 8ul) in
uint_from_bytes_le_lemma (as_seq h0 b);
lo, hi | false |
Hacl.K256.Field.fsti | Hacl.K256.Field.as_felem4 | val as_felem4 (h: mem) (e: lbuffer uint64 4ul) : GTot felem4 | val as_felem4 (h: mem) (e: lbuffer uint64 4ul) : GTot felem4 | let as_felem4 (h:mem) (e:lbuffer uint64 4ul) : GTot felem4 =
let open Lib.Sequence in
let s = as_seq h e in
(s.[3], s.[2], s.[1], s.[0]) | {
"file_name": "code/k256/Hacl.K256.Field.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 72,
"start_col": 0,
"start_line": 69
} | module Hacl.K256.Field
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 BSeq = Lib.ByteSequence
module S = Spec.K256
include Hacl.Spec.K256.Field52.Definitions
module BI = Hacl.Spec.K256.Field52
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
(** Specialized bignum library with a radix-2^{52} *)
inline_for_extraction noextract
let nlimb = 5ul
inline_for_extraction noextract
let felem = lbuffer uint64 nlimb
noextract
let as_felem5 (h:mem) (e:felem) : GTot felem5 =
let open Lib.Sequence in
let s = as_seq h e in
(s.[0], s.[1], s.[2], s.[3], s.[4])
noextract
let as_nat (h:mem) (e:felem) : GTot nat =
as_nat5 (as_felem5 h e)
noextract
let feval (h:mem) (e:felem) : GTot S.felem = as_nat h e % S.prime
noextract
let inv_fully_reduced5 (f:felem5) =
felem_fits5 f (1,1,1,1,1) /\
as_nat5 f < S.prime
noextract
let inv_fully_reduced (h:mem) (e:felem) =
inv_fully_reduced5 (as_felem5 h e)
noextract
let inv_lazy_reduced1_5 (f:felem5) =
felem_fits5 f (1,1,1,1,1)
noextract
let inv_lazy_reduced1 (h:mem) (e:felem) =
inv_lazy_reduced1_5 (as_felem5 h e)
noextract
let inv_lazy_reduced2_5 (f:felem5) =
felem_fits5 f (1,1,1,1,2)
noextract
let inv_lazy_reduced2 (h:mem) (e:felem) =
inv_lazy_reduced2_5 (as_felem5 h e) | {
"checked_file": "/",
"dependencies": [
"Spec.K256.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.K256.Field52.Definitions.fst.checked",
"Hacl.Spec.K256.Field52.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.K256.Field.fsti"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.K256.Field52",
"short_module": "BI"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.K256.Field52.Definitions",
"short_module": null
},
{
"abbrev": true,
"full_module": "Spec.K256",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.K256",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"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"
} | false | h: FStar.Monotonic.HyperStack.mem -> e: Lib.Buffer.lbuffer Lib.IntTypes.uint64 4ul
-> Prims.GTot Hacl.Spec.K256.Field52.Definitions.felem4 | Prims.GTot | [
"sometrivial"
] | [] | [
"FStar.Monotonic.HyperStack.mem",
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint64",
"FStar.UInt32.__uint_to_t",
"FStar.Pervasives.Native.Mktuple4",
"Lib.Sequence.op_String_Access",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Sequence.lseq",
"Lib.IntTypes.int_t",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"FStar.UInt32.uint_to_t",
"FStar.UInt32.t",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Hacl.Spec.K256.Field52.Definitions.felem4"
] | [] | false | false | false | false | false | let as_felem4 (h: mem) (e: lbuffer uint64 4ul) : GTot felem4 =
| let open Lib.Sequence in
let s = as_seq h e in
(s.[ 3 ], s.[ 2 ], s.[ 1 ], s.[ 0 ]) | false |
Pulse.Checker.Prover.Base.fst | Pulse.Checker.Prover.Base.canon_right_aux | val canon_right_aux (g: env) (vps: list vprop) (f: (vprop -> T.Tac bool))
: T.Tac
(vps': list vprop &
fvps: list vprop &
vprop_equiv g (list_as_vprop vps) (list_as_vprop' (list_as_vprop vps') fvps)) | val canon_right_aux (g: env) (vps: list vprop) (f: (vprop -> T.Tac bool))
: T.Tac
(vps': list vprop &
fvps: list vprop &
vprop_equiv g (list_as_vprop vps) (list_as_vprop' (list_as_vprop vps') fvps)) | let rec canon_right_aux (g:env) (vps:list vprop) (f:vprop -> T.Tac bool)
: T.Tac (vps' : list vprop &
fvps : list vprop &
vprop_equiv g (list_as_vprop vps) (list_as_vprop' (list_as_vprop vps') fvps)) =
match vps with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::rest ->
if f hd
then begin
let (| vps', fvps, _ |) = canon_right_aux g rest f in
let v_eq = RU.magic #(vprop_equiv _ _ _) () in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop (hd :: (vps' @ fvps)))
// = list_as_vprop_ctx g [hd] _ rest (vps' @ fvps) (VE_Refl _ _) v_eq
// in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop ((vps'@[hd]) @ fvps))
// = VE_Trans _ _ _ _ v_eq (VE_Sym _ _ _ (vprop_equiv_swap_equiv _ _ _ hd _ (VE_Refl _ _)))
// in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop (vps'@(hd::fvps)))
// = VE_Trans _ _ _ _ v_eq (VE_Sym _ _ _ (list_as_vprop_assoc _ _ _ _)) in
(| vps', hd :: fvps, v_eq |)
end
else begin
let (| vps', pures, _ |) = canon_right_aux g rest f in
let v_eq = RU.magic #(vprop_equiv _ _ _ ) () in //list_as_vprop_ctx g [hd] _ _ _ (VE_Refl _ _) v_eq in
(| hd::vps', pures, v_eq |)
end | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Base.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 7,
"end_line": 65,
"start_col": 0,
"start_line": 33
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Base
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Typing.Combinators
module RU = Pulse.RuntimeUtils
module T = FStar.Tactics.V2
module PS = Pulse.Checker.Prover.Substs
let rec list_as_vprop' (vp:vprop) (fvps:list vprop)
: Tot vprop (decreases fvps) =
match fvps with
| [] -> vp
| hd::tl -> list_as_vprop' (tm_star vp hd) tl | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Base.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
g: Pulse.Typing.Env.env ->
vps: Prims.list Pulse.Syntax.Base.vprop ->
f: (_: Pulse.Syntax.Base.vprop -> FStar.Tactics.Effect.Tac Prims.bool)
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.dtuple3 (Prims.list Pulse.Syntax.Base.vprop)
(fun _ -> Prims.list Pulse.Syntax.Base.vprop)
(fun vps' fvps ->
Pulse.Typing.vprop_equiv g
(Pulse.Typing.Combinators.list_as_vprop vps)
(Pulse.Checker.Prover.Base.list_as_vprop' (Pulse.Typing.Combinators.list_as_vprop vps'
)
fvps))) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Prims.list",
"Pulse.Syntax.Base.vprop",
"Prims.bool",
"FStar.Pervasives.Mkdtuple3",
"Pulse.Typing.vprop_equiv",
"Pulse.Typing.Combinators.list_as_vprop",
"Pulse.Checker.Prover.Base.list_as_vprop'",
"Prims.Nil",
"Pulse.Typing.VE_Refl",
"FStar.Pervasives.dtuple3",
"Prims.Cons",
"Pulse.RuntimeUtils.magic",
"Pulse.Checker.Prover.Base.canon_right_aux"
] | [
"recursion"
] | false | true | false | false | false | let rec canon_right_aux (g: env) (vps: list vprop) (f: (vprop -> T.Tac bool))
: T.Tac
(vps': list vprop &
fvps: list vprop &
vprop_equiv g (list_as_vprop vps) (list_as_vprop' (list_as_vprop vps') fvps)) =
| match vps with
| [] -> (| [], [], VE_Refl _ _ |)
| hd :: rest ->
if f hd
then
let (| vps' , fvps , _ |) = canon_right_aux g rest f in
let v_eq = RU.magic #(vprop_equiv _ _ _) () in
(| vps', hd :: fvps, v_eq |)
else
let (| vps' , pures , _ |) = canon_right_aux g rest f in
let v_eq = RU.magic #(vprop_equiv _ _ _) () in
(| hd :: vps', pures, v_eq |) | false |
Pulse.Checker.Prover.Base.fst | Pulse.Checker.Prover.Base.canon_right | val canon_right
(#g: env)
(#ctxt #frame: term)
(ctxt_frame_typing: tot_typing g (tm_star ctxt frame) tm_vprop)
(f: (vprop -> T.Tac bool))
: T.Tac
(ctxt': term &
tot_typing g (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g (tm_star ctxt' frame)) | val canon_right
(#g: env)
(#ctxt #frame: term)
(ctxt_frame_typing: tot_typing g (tm_star ctxt frame) tm_vprop)
(f: (vprop -> T.Tac bool))
: T.Tac
(ctxt': term &
tot_typing g (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g (tm_star ctxt' frame)) | let canon_right (#g:env) (#ctxt:term) (#frame:term)
(ctxt_frame_typing:tot_typing g (tm_star ctxt frame) tm_vprop)
(f:vprop -> T.Tac bool)
: T.Tac (ctxt':term &
tot_typing g (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g (tm_star ctxt' frame))
= let (| vps', pures, veq |) = canon_right_aux g (vprop_as_list ctxt) f in
let veq : vprop_equiv g ctxt (list_as_vprop' (list_as_vprop vps') pures)
= RU.magic () in
let veq : vprop_equiv g (tm_star ctxt frame) (tm_star (list_as_vprop' (list_as_vprop vps') pures) frame)
= VE_Ctxt _ _ _ _ _ veq (VE_Refl _ _) in
(| _, VP.vprop_equiv_typing_fwd ctxt_frame_typing veq, k_elab_equiv (k_elab_unit _ _) (VE_Refl _ _) veq |) | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Base.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 110,
"end_line": 80,
"start_col": 0,
"start_line": 69
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Base
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Typing.Combinators
module RU = Pulse.RuntimeUtils
module T = FStar.Tactics.V2
module PS = Pulse.Checker.Prover.Substs
let rec list_as_vprop' (vp:vprop) (fvps:list vprop)
: Tot vprop (decreases fvps) =
match fvps with
| [] -> vp
| hd::tl -> list_as_vprop' (tm_star vp hd) tl
let rec canon_right_aux (g:env) (vps:list vprop) (f:vprop -> T.Tac bool)
: T.Tac (vps' : list vprop &
fvps : list vprop &
vprop_equiv g (list_as_vprop vps) (list_as_vprop' (list_as_vprop vps') fvps)) =
match vps with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::rest ->
if f hd
then begin
let (| vps', fvps, _ |) = canon_right_aux g rest f in
let v_eq = RU.magic #(vprop_equiv _ _ _) () in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop (hd :: (vps' @ fvps)))
// = list_as_vprop_ctx g [hd] _ rest (vps' @ fvps) (VE_Refl _ _) v_eq
// in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop ((vps'@[hd]) @ fvps))
// = VE_Trans _ _ _ _ v_eq (VE_Sym _ _ _ (vprop_equiv_swap_equiv _ _ _ hd _ (VE_Refl _ _)))
// in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop (vps'@(hd::fvps)))
// = VE_Trans _ _ _ _ v_eq (VE_Sym _ _ _ (list_as_vprop_assoc _ _ _ _)) in
(| vps', hd :: fvps, v_eq |)
end
else begin
let (| vps', pures, _ |) = canon_right_aux g rest f in
let v_eq = RU.magic #(vprop_equiv _ _ _ ) () in //list_as_vprop_ctx g [hd] _ _ _ (VE_Refl _ _) v_eq in
(| hd::vps', pures, v_eq |)
end
module VP = Pulse.Checker.VPropEquiv | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Base.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": "VP"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ctxt_frame_typing:
Pulse.Typing.tot_typing g (Pulse.Syntax.Base.tm_star ctxt frame) Pulse.Syntax.Base.tm_vprop ->
f: (_: Pulse.Syntax.Base.vprop -> FStar.Tactics.Effect.Tac Prims.bool)
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.dtuple3 Pulse.Syntax.Base.term
(fun ctxt' ->
Pulse.Typing.tot_typing g
(Pulse.Syntax.Base.tm_star ctxt' frame)
Pulse.Syntax.Base.tm_vprop)
(fun ctxt' _ ->
Pulse.Checker.Base.continuation_elaborator g
(Pulse.Syntax.Base.tm_star ctxt frame)
g
(Pulse.Syntax.Base.tm_star ctxt' frame))) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.tm_vprop",
"Pulse.Syntax.Base.vprop",
"Prims.bool",
"Prims.list",
"Pulse.Typing.vprop_equiv",
"Pulse.Typing.Combinators.list_as_vprop",
"Pulse.Typing.Combinators.vprop_as_list",
"Pulse.Checker.Prover.Base.list_as_vprop'",
"FStar.Pervasives.Mkdtuple3",
"Pulse.Checker.Base.continuation_elaborator",
"Pulse.Checker.VPropEquiv.vprop_equiv_typing_fwd",
"Pulse.Checker.Base.k_elab_equiv",
"Pulse.Checker.Base.k_elab_unit",
"Pulse.Typing.VE_Refl",
"Pulse.Typing.VE_Ctxt",
"Pulse.RuntimeUtils.magic",
"FStar.Pervasives.dtuple3",
"Pulse.Checker.Prover.Base.canon_right_aux"
] | [] | false | true | false | false | false | let canon_right
(#g: env)
(#ctxt #frame: term)
(ctxt_frame_typing: tot_typing g (tm_star ctxt frame) tm_vprop)
(f: (vprop -> T.Tac bool))
: T.Tac
(ctxt': term &
tot_typing g (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g (tm_star ctxt' frame)) =
| let (| vps' , pures , veq |) = canon_right_aux g (vprop_as_list ctxt) f in
let veq:vprop_equiv g ctxt (list_as_vprop' (list_as_vprop vps') pures) = RU.magic () in
let veq:vprop_equiv g
(tm_star ctxt frame)
(tm_star (list_as_vprop' (list_as_vprop vps') pures) frame) =
VE_Ctxt _ _ _ _ _ veq (VE_Refl _ _)
in
(|
_,
VP.vprop_equiv_typing_fwd ctxt_frame_typing veq,
k_elab_equiv (k_elab_unit _ _) (VE_Refl _ _) veq
|) | false |
Pulse.Checker.Prover.Base.fst | Pulse.Checker.Prover.Base.add_elims_aux | val add_elims_aux
(#g: env)
(#ctxt #frame: term)
(f: (vprop -> T.Tac bool))
(mk: mk_t)
(ctxt_frame_typing: tot_typing g (tm_star ctxt frame) tm_vprop)
(uvs: env{disjoint uvs g})
: T.Tac
(bool &
(g': env{env_extends g' g /\ disjoint uvs g'} &
ctxt': term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g' (tm_star ctxt' frame))) | val add_elims_aux
(#g: env)
(#ctxt #frame: term)
(f: (vprop -> T.Tac bool))
(mk: mk_t)
(ctxt_frame_typing: tot_typing g (tm_star ctxt frame) tm_vprop)
(uvs: env{disjoint uvs g})
: T.Tac
(bool &
(g': env{env_extends g' g /\ disjoint uvs g'} &
ctxt': term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g' (tm_star ctxt' frame))) | let add_elims_aux (#g:env) (#ctxt:term) (#frame:term)
(f:vprop -> T.Tac bool)
(mk:mk_t)
(ctxt_frame_typing:tot_typing g (tm_star ctxt frame) tm_vprop)
(uvs:env { disjoint uvs g })
: T.Tac (bool &
(g':env { env_extends g' g /\ disjoint uvs g' } &
ctxt':term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g' (tm_star ctxt' frame)))
= let (| ctxt', ctxt'_typing, k |) = canon_right ctxt_frame_typing f in
let progress, (| g', ctxt'', ctxt''_typing, k' |) =
elim_all f mk ctxt'_typing uvs in
progress, (| g', ctxt'', ctxt''_typing, k_elab_trans k k' |) | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Base.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 66,
"end_line": 170,
"start_col": 0,
"start_line": 157
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Base
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Typing.Combinators
module RU = Pulse.RuntimeUtils
module T = FStar.Tactics.V2
module PS = Pulse.Checker.Prover.Substs
let rec list_as_vprop' (vp:vprop) (fvps:list vprop)
: Tot vprop (decreases fvps) =
match fvps with
| [] -> vp
| hd::tl -> list_as_vprop' (tm_star vp hd) tl
let rec canon_right_aux (g:env) (vps:list vprop) (f:vprop -> T.Tac bool)
: T.Tac (vps' : list vprop &
fvps : list vprop &
vprop_equiv g (list_as_vprop vps) (list_as_vprop' (list_as_vprop vps') fvps)) =
match vps with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::rest ->
if f hd
then begin
let (| vps', fvps, _ |) = canon_right_aux g rest f in
let v_eq = RU.magic #(vprop_equiv _ _ _) () in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop (hd :: (vps' @ fvps)))
// = list_as_vprop_ctx g [hd] _ rest (vps' @ fvps) (VE_Refl _ _) v_eq
// in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop ((vps'@[hd]) @ fvps))
// = VE_Trans _ _ _ _ v_eq (VE_Sym _ _ _ (vprop_equiv_swap_equiv _ _ _ hd _ (VE_Refl _ _)))
// in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop (vps'@(hd::fvps)))
// = VE_Trans _ _ _ _ v_eq (VE_Sym _ _ _ (list_as_vprop_assoc _ _ _ _)) in
(| vps', hd :: fvps, v_eq |)
end
else begin
let (| vps', pures, _ |) = canon_right_aux g rest f in
let v_eq = RU.magic #(vprop_equiv _ _ _ ) () in //list_as_vprop_ctx g [hd] _ _ _ (VE_Refl _ _) v_eq in
(| hd::vps', pures, v_eq |)
end
module VP = Pulse.Checker.VPropEquiv
let canon_right (#g:env) (#ctxt:term) (#frame:term)
(ctxt_frame_typing:tot_typing g (tm_star ctxt frame) tm_vprop)
(f:vprop -> T.Tac bool)
: T.Tac (ctxt':term &
tot_typing g (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g (tm_star ctxt' frame))
= let (| vps', pures, veq |) = canon_right_aux g (vprop_as_list ctxt) f in
let veq : vprop_equiv g ctxt (list_as_vprop' (list_as_vprop vps') pures)
= RU.magic () in
let veq : vprop_equiv g (tm_star ctxt frame) (tm_star (list_as_vprop' (list_as_vprop vps') pures) frame)
= VE_Ctxt _ _ _ _ _ veq (VE_Refl _ _) in
(| _, VP.vprop_equiv_typing_fwd ctxt_frame_typing veq, k_elab_equiv (k_elab_unit _ _) (VE_Refl _ _) veq |)
let elim_one (#g:env)
(ctxt:term) (frame:vprop) (p:vprop)
(ctxt_frame_p_typing:tot_typing g (tm_star (tm_star ctxt frame) p) tm_vprop)
(nx:ppname) (e1:st_term) (c1:comp { stateful_comp c1 /\ comp_pre c1 == p })
(e1_typing:st_typing g e1 c1)
(uvs:env { disjoint uvs g })
: T.Tac (g':env { env_extends g' g /\ disjoint uvs g' } &
ctxt':term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star (tm_star ctxt frame) p) g' (tm_star ctxt' frame)) =
let ctxt_frame_typing = star_typing_inversion_l ctxt_frame_p_typing in
let x = fresh (push_env g uvs) in
let k =
continuation_elaborator_with_bind (tm_star ctxt frame) e1_typing ctxt_frame_p_typing (nx, x) in
let g' = push_binding g x nx (comp_res c1) in
let ctxt' = tm_star (open_term_nv (comp_post c1) (nx, x)) ctxt in
let veq
: vprop_equiv g' (tm_star (open_term_nv (comp_post c1) (nx, x)) (tm_star ctxt frame))
(tm_star ctxt' frame) = VE_Assoc _ _ _ _ in
let k
: continuation_elaborator
g (tm_star (tm_star ctxt frame) p)
g' (tm_star ctxt' frame) =
k_elab_equiv
#g #g'
#(tm_star (tm_star ctxt frame) p)
#(tm_star (tm_star ctxt frame) p)
#(tm_star (open_term_nv (comp_post c1) (nx, x)) (tm_star ctxt frame))
#(tm_star ctxt' frame)
k (VE_Refl g (tm_star (tm_star ctxt frame) p)) veq in
let ctxt'_frame_typing : tot_typing g' (tm_star ctxt' frame) tm_vprop = RU.magic () in
env_extends_push g x ppname_default (comp_res c1);
(| g', ctxt', ctxt'_frame_typing, k |)
let rec elim_all (#g:env)
(f:vprop -> T.Tac bool)
(mk:mk_t)
(#ctxt:term) (#frame:term) (ctxt_frame_typing:tot_typing g (tm_star ctxt frame) tm_vprop)
(uvs:env { disjoint uvs g })
: T.Tac (bool &
(g':env { env_extends g' g /\ disjoint uvs g' } &
ctxt':term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g' (tm_star ctxt' frame)))
= match ctxt.t with
| Tm_Star ctxt' p ->
let p_typing =
star_typing_inversion_r #_ #ctxt' #p (star_typing_inversion_l ctxt_frame_typing) in
if f p
then match mk #_ #p p_typing with
| Some (| nx, e1, c1, e1_typing |) ->
let (| g', _, ctxt_typing', k |) =
elim_one ctxt' frame p (RU.magic ()) nx e1 c1 e1_typing uvs in
let k
: continuation_elaborator g (tm_star (tm_star ctxt' frame) p)
g' (tm_star _ frame) = k in
let k
: continuation_elaborator g (tm_star (tm_star ctxt' p) frame)
g' (tm_star _ frame) =
k_elab_equiv k
(RU.magic ()) (VE_Refl _ _) in
let _, (| g'', ctxt'', ctxt_typing'', k' |) =
elim_all #g' f mk ctxt_typing' uvs in
true, (| g'', ctxt'', ctxt_typing'', k_elab_trans k k' |)
| None ->
false, (| g, ctxt, ctxt_frame_typing, k_elab_unit _ _ |)
else begin
false, (| g, ctxt, ctxt_frame_typing, k_elab_unit _ _ |)
end
| _ ->
false, (| g, ctxt, ctxt_frame_typing, k_elab_unit _ _ |) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Base.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": "VP"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: (_: Pulse.Syntax.Base.vprop -> FStar.Tactics.Effect.Tac Prims.bool) ->
mk: Pulse.Checker.Prover.Base.mk_t ->
ctxt_frame_typing:
Pulse.Typing.tot_typing g (Pulse.Syntax.Base.tm_star ctxt frame) Pulse.Syntax.Base.tm_vprop ->
uvs: Pulse.Typing.Env.env{Pulse.Typing.Env.disjoint uvs g}
-> FStar.Tactics.Effect.Tac
(Prims.bool *
FStar.Pervasives.dtuple4 (g':
Pulse.Typing.Env.env
{Pulse.Typing.Env.env_extends g' g /\ Pulse.Typing.Env.disjoint uvs g'})
(fun _ -> Pulse.Syntax.Base.term)
(fun g' ctxt' ->
Pulse.Typing.tot_typing g'
(Pulse.Syntax.Base.tm_star ctxt' frame)
Pulse.Syntax.Base.tm_vprop)
(fun g' ctxt' _ ->
Pulse.Checker.Base.continuation_elaborator g
(Pulse.Syntax.Base.tm_star ctxt frame)
g'
(Pulse.Syntax.Base.tm_star ctxt' frame))) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.vprop",
"Prims.bool",
"Pulse.Checker.Prover.Base.mk_t",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.tm_vprop",
"Pulse.Typing.Env.disjoint",
"Pulse.Checker.Base.continuation_elaborator",
"Prims.l_and",
"Pulse.Typing.Env.env_extends",
"FStar.Pervasives.Native.Mktuple2",
"FStar.Pervasives.dtuple4",
"FStar.Pervasives.Mkdtuple4",
"Pulse.Checker.Base.k_elab_trans",
"FStar.Pervasives.Native.tuple2",
"Pulse.Checker.Prover.Base.elim_all",
"FStar.Pervasives.dtuple3",
"Pulse.Checker.Prover.Base.canon_right"
] | [] | false | true | false | false | false | let add_elims_aux
(#g: env)
(#ctxt #frame: term)
(f: (vprop -> T.Tac bool))
(mk: mk_t)
(ctxt_frame_typing: tot_typing g (tm_star ctxt frame) tm_vprop)
(uvs: env{disjoint uvs g})
: T.Tac
(bool &
(g': env{env_extends g' g /\ disjoint uvs g'} &
ctxt': term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g' (tm_star ctxt' frame))) =
| let (| ctxt' , ctxt'_typing , k |) = canon_right ctxt_frame_typing f in
let progress, (| g' , ctxt'' , ctxt''_typing , k' |) = elim_all f mk ctxt'_typing uvs in
progress, (| g', ctxt'', ctxt''_typing, k_elab_trans k k' |) | false |
Hacl.Impl.Poly1305.Bignum128.fst | Hacl.Impl.Poly1305.Bignum128.uints64_to_bytes_le | val uints64_to_bytes_le:
b:lbuffer uint8 16ul
-> lo:uint64
-> hi:uint64 ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 ->
modifies (loc b) h0 h1 /\
as_seq h1 b == BSeq.nat_to_bytes_le 16 (v hi * pow2 64 + v lo)) | val uints64_to_bytes_le:
b:lbuffer uint8 16ul
-> lo:uint64
-> hi:uint64 ->
Stack unit
(requires fun h -> live h b)
(ensures fun h0 _ h1 ->
modifies (loc b) h0 h1 /\
as_seq h1 b == BSeq.nat_to_bytes_le 16 (v hi * pow2 64 + v lo)) | let uints64_to_bytes_le b r0 r1 =
let h0 = ST.get () in
update_sub_f h0 b 0ul 8ul
(fun h -> BSeq.uint_to_bytes_le #U64 r0)
(fun _ -> uint_to_bytes_le (sub b 0ul 8ul) r0);
let h1 = ST.get () in
update_sub_f h1 b 8ul 8ul
(fun h -> BSeq.uint_to_bytes_le #U64 r1)
(fun _ -> uint_to_bytes_le (sub b 8ul 8ul) r1);
//uint_to_bytes_le (sub b 0ul 8ul) r0;
//uint_to_bytes_le (sub b 8ul 8ul) r1;
let h2 = ST.get () in
uints64_to_bytes_le_lemma r0 r1;
LSeq.eq_intro (LSeq.sub (as_seq h2 b) 0 8) (BSeq.uint_to_bytes_le #U64 r0);
LSeq.lemma_concat2
8 (BSeq.uint_to_bytes_le #U64 r0)
8 (BSeq.uint_to_bytes_le #U64 r1) (as_seq h2 b) | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Bignum128.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 51,
"end_line": 45,
"start_col": 0,
"start_line": 29
} | module Hacl.Impl.Poly1305.Bignum128
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Poly1305.Lemmas
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
friend FStar.UInt128
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let uints64_from_bytes_le b =
let h0 = ST.get () in
let lo = uint_from_bytes_le #U64 (sub b 0ul 8ul) in
let hi = uint_from_bytes_le #U64 (sub b 8ul 8ul) in
uint_from_bytes_le_lemma (as_seq h0 b);
lo, hi | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt128.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Poly1305.Bignum128.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Lib.Buffer.lbuffer Lib.IntTypes.uint8 16ul -> lo: Lib.IntTypes.uint64 -> hi: Lib.IntTypes.uint64
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Lib.Buffer.lbuffer",
"Lib.IntTypes.uint8",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.uint64",
"Lib.Sequence.lemma_concat2",
"Lib.IntTypes.uint_t",
"Lib.IntTypes.U8",
"Lib.IntTypes.SEC",
"Lib.ByteSequence.uint_to_bytes_le",
"Lib.IntTypes.U64",
"Lib.Buffer.as_seq",
"Lib.Buffer.MUT",
"Prims.unit",
"Lib.Sequence.eq_intro",
"Lib.Sequence.sub",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Impl.Poly1305.Lemmas.uints64_to_bytes_le_lemma",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Lib.Buffer.update_sub_f",
"Lib.Sequence.lseq",
"Lib.ByteBuffer.uint_to_bytes_le",
"Lib.Buffer.lbuffer_t",
"Lib.IntTypes.int_t",
"Lib.IntTypes.mk_int",
"Lib.Buffer.sub"
] | [] | false | true | false | false | false | let uints64_to_bytes_le b r0 r1 =
| let h0 = ST.get () in
update_sub_f h0
b
0ul
8ul
(fun h -> BSeq.uint_to_bytes_le #U64 r0)
(fun _ -> uint_to_bytes_le (sub b 0ul 8ul) r0);
let h1 = ST.get () in
update_sub_f h1
b
8ul
8ul
(fun h -> BSeq.uint_to_bytes_le #U64 r1)
(fun _ -> uint_to_bytes_le (sub b 8ul 8ul) r1);
let h2 = ST.get () in
uints64_to_bytes_le_lemma r0 r1;
LSeq.eq_intro (LSeq.sub (as_seq h2 b) 0 8) (BSeq.uint_to_bytes_le #U64 r0);
LSeq.lemma_concat2 8 (BSeq.uint_to_bytes_le #U64 r0) 8 (BSeq.uint_to_bytes_le #U64 r1) (as_seq h2 b) | false |
Pulse.Checker.fst | Pulse.Checker.default_binder_annot | val default_binder_annot : Pulse.Syntax.Base.binder | let default_binder_annot = mk_binder_ppname tm_unknown ppname_default | {
"file_name": "lib/steel/pulse/Pulse.Checker.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 69,
"end_line": 57,
"start_col": 0,
"start_line": 57
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module T = FStar.Tactics.V2
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Reflection.Util
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Checker.Pure
open Pulse.Checker.Bind
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Base
module P = Pulse.Syntax.Printer
module RTB = FStar.Tactics.Builtins
module FV = Pulse.Typing.FV
module RU = Pulse.RuntimeUtils
module Metatheory = Pulse.Typing.Metatheory
module Abs = Pulse.Checker.Abs
module If = Pulse.Checker.If
module Bind = Pulse.Checker.Bind
module Match = Pulse.Checker.Match
module WithLocal = Pulse.Checker.WithLocal
module WithLocalArray = Pulse.Checker.WithLocalArray
module While = Pulse.Checker.While
module STApp = Pulse.Checker.STApp
module Exists = Pulse.Checker.Exists
module Par = Pulse.Checker.Par
module Admit = Pulse.Checker.Admit
module Return = Pulse.Checker.Return
module Rewrite = Pulse.Checker.Rewrite
module WithInv = Pulse.Checker.WithInv
let terms_to_string (t:list term)
: T.Tac string
= String.concat "\n" (T.map Pulse.Syntax.Printer.term_to_string t) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.FV.fsti.checked",
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Checker.WithLocalArray.fsti.checked",
"Pulse.Checker.WithLocal.fsti.checked",
"Pulse.Checker.WithInv.fsti.checked",
"Pulse.Checker.While.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Unreachable.fsti.checked",
"Pulse.Checker.STApp.fsti.checked",
"Pulse.Checker.Rewrite.fsti.checked",
"Pulse.Checker.Return.fsti.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Par.fsti.checked",
"Pulse.Checker.Match.fsti.checked",
"Pulse.Checker.IntroPure.fsti.checked",
"Pulse.Checker.If.fsti.checked",
"Pulse.Checker.Exists.fsti.checked",
"Pulse.Checker.Bind.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"Pulse.Checker.AssertWithBinders.fsti.checked",
"Pulse.Checker.Admit.fsti.checked",
"Pulse.Checker.Abs.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Builtins.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.WithInv",
"short_module": "WithInv"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Rewrite",
"short_module": "Rewrite"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Return",
"short_module": "Return"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Admit",
"short_module": "Admit"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Par",
"short_module": "Par"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Exists",
"short_module": "Exists"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.STApp",
"short_module": "STApp"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.While",
"short_module": "While"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.WithLocalArray",
"short_module": "WithLocalArray"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.WithLocal",
"short_module": "WithLocal"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Match",
"short_module": "Match"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Bind",
"short_module": "Bind"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.If",
"short_module": "If"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Abs",
"short_module": "Abs"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.FV",
"short_module": "FV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Bind",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Pulse.Syntax.Base.binder | Prims.Tot | [
"total"
] | [] | [
"Pulse.Syntax.Base.mk_binder_ppname",
"Pulse.Syntax.Base.tm_unknown",
"Pulse.Syntax.Base.ppname_default"
] | [] | false | false | false | true | false | let default_binder_annot =
| mk_binder_ppname tm_unknown ppname_default | false |
|
Pulse.Checker.fst | Pulse.Checker.terms_to_string | val terms_to_string (t: list term) : T.Tac string | val terms_to_string (t: list term) : T.Tac string | let terms_to_string (t:list term)
: T.Tac string
= String.concat "\n" (T.map Pulse.Syntax.Printer.term_to_string t) | {
"file_name": "lib/steel/pulse/Pulse.Checker.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 68,
"end_line": 55,
"start_col": 0,
"start_line": 53
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module T = FStar.Tactics.V2
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Reflection.Util
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Checker.Pure
open Pulse.Checker.Bind
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Base
module P = Pulse.Syntax.Printer
module RTB = FStar.Tactics.Builtins
module FV = Pulse.Typing.FV
module RU = Pulse.RuntimeUtils
module Metatheory = Pulse.Typing.Metatheory
module Abs = Pulse.Checker.Abs
module If = Pulse.Checker.If
module Bind = Pulse.Checker.Bind
module Match = Pulse.Checker.Match
module WithLocal = Pulse.Checker.WithLocal
module WithLocalArray = Pulse.Checker.WithLocalArray
module While = Pulse.Checker.While
module STApp = Pulse.Checker.STApp
module Exists = Pulse.Checker.Exists
module Par = Pulse.Checker.Par
module Admit = Pulse.Checker.Admit
module Return = Pulse.Checker.Return
module Rewrite = Pulse.Checker.Rewrite
module WithInv = Pulse.Checker.WithInv | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.FV.fsti.checked",
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Checker.WithLocalArray.fsti.checked",
"Pulse.Checker.WithLocal.fsti.checked",
"Pulse.Checker.WithInv.fsti.checked",
"Pulse.Checker.While.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Unreachable.fsti.checked",
"Pulse.Checker.STApp.fsti.checked",
"Pulse.Checker.Rewrite.fsti.checked",
"Pulse.Checker.Return.fsti.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Par.fsti.checked",
"Pulse.Checker.Match.fsti.checked",
"Pulse.Checker.IntroPure.fsti.checked",
"Pulse.Checker.If.fsti.checked",
"Pulse.Checker.Exists.fsti.checked",
"Pulse.Checker.Bind.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"Pulse.Checker.AssertWithBinders.fsti.checked",
"Pulse.Checker.Admit.fsti.checked",
"Pulse.Checker.Abs.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Builtins.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.WithInv",
"short_module": "WithInv"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Rewrite",
"short_module": "Rewrite"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Return",
"short_module": "Return"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Admit",
"short_module": "Admit"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Par",
"short_module": "Par"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Exists",
"short_module": "Exists"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.STApp",
"short_module": "STApp"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.While",
"short_module": "While"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.WithLocalArray",
"short_module": "WithLocalArray"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.WithLocal",
"short_module": "WithLocal"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Match",
"short_module": "Match"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Bind",
"short_module": "Bind"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.If",
"short_module": "If"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Abs",
"short_module": "Abs"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.FV",
"short_module": "FV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Bind",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | t: Prims.list Pulse.Syntax.Base.term -> FStar.Tactics.Effect.Tac Prims.string | FStar.Tactics.Effect.Tac | [] | [] | [
"Prims.list",
"Pulse.Syntax.Base.term",
"FStar.String.concat",
"Prims.string",
"FStar.Tactics.Util.map",
"Pulse.Syntax.Printer.term_to_string"
] | [] | false | true | false | false | false | let terms_to_string (t: list term) : T.Tac string =
| String.concat "\n" (T.map Pulse.Syntax.Printer.term_to_string t) | false |
Pulse.Checker.Prover.Base.fst | Pulse.Checker.Prover.Base.add_elims | val add_elims (#g:env) (#ctxt:term) (#frame:term)
(f:vprop -> T.Tac bool)
(mk:mk_t)
(ctxt_typing:tot_typing g (tm_star ctxt frame) tm_vprop)
(uvs:env { disjoint uvs g })
: T.Tac (g':env { env_extends g' g /\ disjoint uvs g' } &
ctxt':term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g' (tm_star ctxt' frame)) | val add_elims (#g:env) (#ctxt:term) (#frame:term)
(f:vprop -> T.Tac bool)
(mk:mk_t)
(ctxt_typing:tot_typing g (tm_star ctxt frame) tm_vprop)
(uvs:env { disjoint uvs g })
: T.Tac (g':env { env_extends g' g /\ disjoint uvs g' } &
ctxt':term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g' (tm_star ctxt' frame)) | let rec add_elims (#g:env) (#ctxt:term) (#frame:term)
(f:vprop -> T.Tac bool)
(mk:mk_t)
(ctxt_typing:tot_typing g (tm_star ctxt frame) tm_vprop)
(uvs:env { disjoint uvs g })
: T.Tac (g':env { env_extends g' g /\ disjoint uvs g' } &
ctxt':term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g' (tm_star ctxt' frame))
= let progress, res = add_elims_aux f mk ctxt_typing uvs in
if not progress
then res
else (
let (| g', ctxt', ctxt'_typing, k |) = res in
let (| g'', ctxt'', ctxt''_typing, k' |) = add_elims f mk ctxt'_typing uvs in
(| g'', ctxt'', ctxt''_typing, k_elab_trans k k' |)
) | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Base.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 6,
"end_line": 188,
"start_col": 0,
"start_line": 172
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Base
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Typing.Combinators
module RU = Pulse.RuntimeUtils
module T = FStar.Tactics.V2
module PS = Pulse.Checker.Prover.Substs
let rec list_as_vprop' (vp:vprop) (fvps:list vprop)
: Tot vprop (decreases fvps) =
match fvps with
| [] -> vp
| hd::tl -> list_as_vprop' (tm_star vp hd) tl
let rec canon_right_aux (g:env) (vps:list vprop) (f:vprop -> T.Tac bool)
: T.Tac (vps' : list vprop &
fvps : list vprop &
vprop_equiv g (list_as_vprop vps) (list_as_vprop' (list_as_vprop vps') fvps)) =
match vps with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::rest ->
if f hd
then begin
let (| vps', fvps, _ |) = canon_right_aux g rest f in
let v_eq = RU.magic #(vprop_equiv _ _ _) () in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop (hd :: (vps' @ fvps)))
// = list_as_vprop_ctx g [hd] _ rest (vps' @ fvps) (VE_Refl _ _) v_eq
// in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop ((vps'@[hd]) @ fvps))
// = VE_Trans _ _ _ _ v_eq (VE_Sym _ _ _ (vprop_equiv_swap_equiv _ _ _ hd _ (VE_Refl _ _)))
// in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop (vps'@(hd::fvps)))
// = VE_Trans _ _ _ _ v_eq (VE_Sym _ _ _ (list_as_vprop_assoc _ _ _ _)) in
(| vps', hd :: fvps, v_eq |)
end
else begin
let (| vps', pures, _ |) = canon_right_aux g rest f in
let v_eq = RU.magic #(vprop_equiv _ _ _ ) () in //list_as_vprop_ctx g [hd] _ _ _ (VE_Refl _ _) v_eq in
(| hd::vps', pures, v_eq |)
end
module VP = Pulse.Checker.VPropEquiv
let canon_right (#g:env) (#ctxt:term) (#frame:term)
(ctxt_frame_typing:tot_typing g (tm_star ctxt frame) tm_vprop)
(f:vprop -> T.Tac bool)
: T.Tac (ctxt':term &
tot_typing g (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g (tm_star ctxt' frame))
= let (| vps', pures, veq |) = canon_right_aux g (vprop_as_list ctxt) f in
let veq : vprop_equiv g ctxt (list_as_vprop' (list_as_vprop vps') pures)
= RU.magic () in
let veq : vprop_equiv g (tm_star ctxt frame) (tm_star (list_as_vprop' (list_as_vprop vps') pures) frame)
= VE_Ctxt _ _ _ _ _ veq (VE_Refl _ _) in
(| _, VP.vprop_equiv_typing_fwd ctxt_frame_typing veq, k_elab_equiv (k_elab_unit _ _) (VE_Refl _ _) veq |)
let elim_one (#g:env)
(ctxt:term) (frame:vprop) (p:vprop)
(ctxt_frame_p_typing:tot_typing g (tm_star (tm_star ctxt frame) p) tm_vprop)
(nx:ppname) (e1:st_term) (c1:comp { stateful_comp c1 /\ comp_pre c1 == p })
(e1_typing:st_typing g e1 c1)
(uvs:env { disjoint uvs g })
: T.Tac (g':env { env_extends g' g /\ disjoint uvs g' } &
ctxt':term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star (tm_star ctxt frame) p) g' (tm_star ctxt' frame)) =
let ctxt_frame_typing = star_typing_inversion_l ctxt_frame_p_typing in
let x = fresh (push_env g uvs) in
let k =
continuation_elaborator_with_bind (tm_star ctxt frame) e1_typing ctxt_frame_p_typing (nx, x) in
let g' = push_binding g x nx (comp_res c1) in
let ctxt' = tm_star (open_term_nv (comp_post c1) (nx, x)) ctxt in
let veq
: vprop_equiv g' (tm_star (open_term_nv (comp_post c1) (nx, x)) (tm_star ctxt frame))
(tm_star ctxt' frame) = VE_Assoc _ _ _ _ in
let k
: continuation_elaborator
g (tm_star (tm_star ctxt frame) p)
g' (tm_star ctxt' frame) =
k_elab_equiv
#g #g'
#(tm_star (tm_star ctxt frame) p)
#(tm_star (tm_star ctxt frame) p)
#(tm_star (open_term_nv (comp_post c1) (nx, x)) (tm_star ctxt frame))
#(tm_star ctxt' frame)
k (VE_Refl g (tm_star (tm_star ctxt frame) p)) veq in
let ctxt'_frame_typing : tot_typing g' (tm_star ctxt' frame) tm_vprop = RU.magic () in
env_extends_push g x ppname_default (comp_res c1);
(| g', ctxt', ctxt'_frame_typing, k |)
let rec elim_all (#g:env)
(f:vprop -> T.Tac bool)
(mk:mk_t)
(#ctxt:term) (#frame:term) (ctxt_frame_typing:tot_typing g (tm_star ctxt frame) tm_vprop)
(uvs:env { disjoint uvs g })
: T.Tac (bool &
(g':env { env_extends g' g /\ disjoint uvs g' } &
ctxt':term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g' (tm_star ctxt' frame)))
= match ctxt.t with
| Tm_Star ctxt' p ->
let p_typing =
star_typing_inversion_r #_ #ctxt' #p (star_typing_inversion_l ctxt_frame_typing) in
if f p
then match mk #_ #p p_typing with
| Some (| nx, e1, c1, e1_typing |) ->
let (| g', _, ctxt_typing', k |) =
elim_one ctxt' frame p (RU.magic ()) nx e1 c1 e1_typing uvs in
let k
: continuation_elaborator g (tm_star (tm_star ctxt' frame) p)
g' (tm_star _ frame) = k in
let k
: continuation_elaborator g (tm_star (tm_star ctxt' p) frame)
g' (tm_star _ frame) =
k_elab_equiv k
(RU.magic ()) (VE_Refl _ _) in
let _, (| g'', ctxt'', ctxt_typing'', k' |) =
elim_all #g' f mk ctxt_typing' uvs in
true, (| g'', ctxt'', ctxt_typing'', k_elab_trans k k' |)
| None ->
false, (| g, ctxt, ctxt_frame_typing, k_elab_unit _ _ |)
else begin
false, (| g, ctxt, ctxt_frame_typing, k_elab_unit _ _ |)
end
| _ ->
false, (| g, ctxt, ctxt_frame_typing, k_elab_unit _ _ |)
let add_elims_aux (#g:env) (#ctxt:term) (#frame:term)
(f:vprop -> T.Tac bool)
(mk:mk_t)
(ctxt_frame_typing:tot_typing g (tm_star ctxt frame) tm_vprop)
(uvs:env { disjoint uvs g })
: T.Tac (bool &
(g':env { env_extends g' g /\ disjoint uvs g' } &
ctxt':term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g' (tm_star ctxt' frame)))
= let (| ctxt', ctxt'_typing, k |) = canon_right ctxt_frame_typing f in
let progress, (| g', ctxt'', ctxt''_typing, k' |) =
elim_all f mk ctxt'_typing uvs in
progress, (| g', ctxt'', ctxt''_typing, k_elab_trans k k' |) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Base.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": "VP"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
f: (_: Pulse.Syntax.Base.vprop -> FStar.Tactics.Effect.Tac Prims.bool) ->
mk: Pulse.Checker.Prover.Base.mk_t ->
ctxt_typing:
Pulse.Typing.tot_typing g (Pulse.Syntax.Base.tm_star ctxt frame) Pulse.Syntax.Base.tm_vprop ->
uvs: Pulse.Typing.Env.env{Pulse.Typing.Env.disjoint uvs g}
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.dtuple4 (g':
Pulse.Typing.Env.env
{Pulse.Typing.Env.env_extends g' g /\ Pulse.Typing.Env.disjoint uvs g'})
(fun _ -> Pulse.Syntax.Base.term)
(fun g' ctxt' ->
Pulse.Typing.tot_typing g'
(Pulse.Syntax.Base.tm_star ctxt' frame)
Pulse.Syntax.Base.tm_vprop)
(fun g' ctxt' _ ->
Pulse.Checker.Base.continuation_elaborator g
(Pulse.Syntax.Base.tm_star ctxt frame)
g'
(Pulse.Syntax.Base.tm_star ctxt' frame))) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.vprop",
"Prims.bool",
"Pulse.Checker.Prover.Base.mk_t",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.tm_vprop",
"Pulse.Typing.Env.disjoint",
"FStar.Pervasives.dtuple4",
"Prims.l_and",
"Pulse.Typing.Env.env_extends",
"Pulse.Checker.Base.continuation_elaborator",
"Prims.op_Negation",
"FStar.Pervasives.Mkdtuple4",
"Pulse.Checker.Base.k_elab_trans",
"Pulse.Checker.Prover.Base.add_elims",
"FStar.Pervasives.Native.tuple2",
"Pulse.Checker.Prover.Base.add_elims_aux"
] | [
"recursion"
] | false | true | false | false | false | let rec add_elims
(#g: env)
(#ctxt #frame: term)
(f: (vprop -> T.Tac bool))
(mk: mk_t)
(ctxt_typing: tot_typing g (tm_star ctxt frame) tm_vprop)
(uvs: env{disjoint uvs g})
: T.Tac
(g': env{env_extends g' g /\ disjoint uvs g'} &
ctxt': term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g' (tm_star ctxt' frame)) =
| let progress, res = add_elims_aux f mk ctxt_typing uvs in
if not progress
then res
else
(let (| g' , ctxt' , ctxt'_typing , k |) = res in
let (| g'' , ctxt'' , ctxt''_typing , k' |) = add_elims f mk ctxt'_typing uvs in
(| g'', ctxt'', ctxt''_typing, k_elab_trans k k' |)) | false |
LowParse.Low.Endianness.fst | LowParse.Low.Endianness.store_post_modifies | val store_post_modifies
(#a: Type)
(#rrel #rel: B.srel a)
(b: B.mbuffer a rrel rel)
(i: nat)
(j: nat{i + j <= B.length b})
(predicate: (Seq.seq a -> Type))
(h0 h1: HS.mem)
: Lemma (requires (B.live h0 b /\ LE.store_post b i j predicate h0 () h1))
(ensures (B.modifies (B.loc_buffer_from_to b (U32.uint_to_t i) (U32.uint_to_t (i + j))) h0 h1)
) | val store_post_modifies
(#a: Type)
(#rrel #rel: B.srel a)
(b: B.mbuffer a rrel rel)
(i: nat)
(j: nat{i + j <= B.length b})
(predicate: (Seq.seq a -> Type))
(h0 h1: HS.mem)
: Lemma (requires (B.live h0 b /\ LE.store_post b i j predicate h0 () h1))
(ensures (B.modifies (B.loc_buffer_from_to b (U32.uint_to_t i) (U32.uint_to_t (i + j))) h0 h1)
) | let store_post_modifies
(#a:Type) (#rrel #rel:B.srel a) (b:B.mbuffer a rrel rel)
(i:nat) (j:nat{i + j <= B.length b}) (predicate:Seq.seq a -> Type)
(h0: HS.mem)
(h1: HS.mem)
: Lemma
(requires (
B.live h0 b /\
LE.store_post b i j predicate h0 () h1
))
(ensures (
B.modifies (B.loc_buffer_from_to b (U32.uint_to_t i) (U32.uint_to_t (i + j))) h0 h1
))
= B.modifies_loc_buffer_from_to_intro b (U32.uint_to_t i) (U32.uint_to_t (i + j)) B.loc_none h0 h1 | {
"file_name": "src/lowparse/LowParse.Low.Endianness.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 98,
"end_line": 59,
"start_col": 0,
"start_line": 46
} | module LowParse.Low.Endianness
include LowParse.Low.Base
include LowStar.Endianness
module B = LowStar.Buffer
module HS = FStar.HyperStack
module Seq = FStar.Seq
module LE = LowStar.Endianness
module U32 = FStar.UInt32
let writable_store_pre
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(i: nat)
(j: nat)
(predicate:Seq.seq byte -> Type)
(h: HS.mem)
: Lemma
(requires (
writable b i (i + j) h /\
i + j <= B.length b
))
(ensures (
LE.store_pre b i j predicate h
))
= let sb = B.as_seq h b in
let len = B.length b in
let phi
(s: Seq.seq byte)
: Lemma
(requires (
Seq.length s == len /\
Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\
Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\
predicate (Seq.slice s i (i + j))
))
(ensures (
rel sb s
))
= assert (sb `Seq.equal` Seq.replace_subseq sb i (i + j) (Seq.slice sb i (i + j)));
assert (s `Seq.equal` Seq.replace_subseq sb i (i + j) (Seq.slice s i (i + j)))
in
Classical.forall_intro (Classical.move_requires phi) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Endianness.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Endianness.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Endianness",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: LowStar.Monotonic.Buffer.mbuffer a rrel rel ->
i: Prims.nat ->
j: Prims.nat{i + j <= LowStar.Monotonic.Buffer.length b} ->
predicate: (_: FStar.Seq.Base.seq a -> Type0) ->
h0: FStar.Monotonic.HyperStack.mem ->
h1: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowStar.Monotonic.Buffer.live h0 b /\ LowStar.Endianness.store_post b i j predicate h0 () h1
)
(ensures
LowStar.Monotonic.Buffer.modifies (LowStar.Monotonic.Buffer.loc_buffer_from_to b
(FStar.UInt32.uint_to_t i)
(FStar.UInt32.uint_to_t (i + j)))
h0
h1) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"LowStar.Monotonic.Buffer.length",
"FStar.Seq.Base.seq",
"FStar.Monotonic.HyperStack.mem",
"LowStar.Monotonic.Buffer.modifies_loc_buffer_from_to_intro",
"FStar.UInt32.uint_to_t",
"LowStar.Monotonic.Buffer.loc_none",
"Prims.unit",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"LowStar.Endianness.store_post",
"Prims.squash",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer_from_to",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | true | false | true | false | false | let store_post_modifies
(#a: Type)
(#rrel #rel: B.srel a)
(b: B.mbuffer a rrel rel)
(i: nat)
(j: nat{i + j <= B.length b})
(predicate: (Seq.seq a -> Type))
(h0 h1: HS.mem)
: Lemma (requires (B.live h0 b /\ LE.store_post b i j predicate h0 () h1))
(ensures (B.modifies (B.loc_buffer_from_to b (U32.uint_to_t i) (U32.uint_to_t (i + j))) h0 h1)
) =
| B.modifies_loc_buffer_from_to_intro b (U32.uint_to_t i) (U32.uint_to_t (i + j)) B.loc_none h0 h1 | false |
Hacl.Streaming.MD.fst | Hacl.Streaming.MD.uint8 | val uint8 : Type0 | let uint8 = Lib.IntTypes.uint8 | {
"file_name": "code/streaming/Hacl.Streaming.MD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 30,
"end_line": 25,
"start_col": 0,
"start_line": 25
} | module Hacl.Streaming.MD
open FStar.HyperStack.ST
/// This file is poorly named. It contains a generic type class instantiation
/// for the streaming functor for any algorithm that fits within the agile hash
/// infrastructure.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.MD.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.uint8"
] | [] | false | false | false | true | true | let uint8 =
| Lib.IntTypes.uint8 | false |
|
Hacl.Streaming.MD.fst | Hacl.Streaming.MD.uint32 | val uint32 : Type0 | let uint32 = Lib.IntTypes.uint32 | {
"file_name": "code/streaming/Hacl.Streaming.MD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 32,
"end_line": 28,
"start_col": 0,
"start_line": 28
} | module Hacl.Streaming.MD
open FStar.HyperStack.ST
/// This file is poorly named. It contains a generic type class instantiation
/// for the streaming functor for any algorithm that fits within the agile hash
/// infrastructure.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8 | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.MD.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Lib.IntTypes.uint32"
] | [] | false | false | false | true | true | let uint32 =
| Lib.IntTypes.uint32 | false |
|
Pulse.Checker.Prover.Base.fst | Pulse.Checker.Prover.Base.elim_one | val elim_one
(#g: env)
(ctxt: term)
(frame p: vprop)
(ctxt_frame_p_typing: tot_typing g (tm_star (tm_star ctxt frame) p) tm_vprop)
(nx: ppname)
(e1: st_term)
(c1: comp{stateful_comp c1 /\ comp_pre c1 == p})
(e1_typing: st_typing g e1 c1)
(uvs: env{disjoint uvs g})
: T.Tac
(g': env{env_extends g' g /\ disjoint uvs g'} &
ctxt': term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star (tm_star ctxt frame) p) g' (tm_star ctxt' frame)) | val elim_one
(#g: env)
(ctxt: term)
(frame p: vprop)
(ctxt_frame_p_typing: tot_typing g (tm_star (tm_star ctxt frame) p) tm_vprop)
(nx: ppname)
(e1: st_term)
(c1: comp{stateful_comp c1 /\ comp_pre c1 == p})
(e1_typing: st_typing g e1 c1)
(uvs: env{disjoint uvs g})
: T.Tac
(g': env{env_extends g' g /\ disjoint uvs g'} &
ctxt': term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star (tm_star ctxt frame) p) g' (tm_star ctxt' frame)) | let elim_one (#g:env)
(ctxt:term) (frame:vprop) (p:vprop)
(ctxt_frame_p_typing:tot_typing g (tm_star (tm_star ctxt frame) p) tm_vprop)
(nx:ppname) (e1:st_term) (c1:comp { stateful_comp c1 /\ comp_pre c1 == p })
(e1_typing:st_typing g e1 c1)
(uvs:env { disjoint uvs g })
: T.Tac (g':env { env_extends g' g /\ disjoint uvs g' } &
ctxt':term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star (tm_star ctxt frame) p) g' (tm_star ctxt' frame)) =
let ctxt_frame_typing = star_typing_inversion_l ctxt_frame_p_typing in
let x = fresh (push_env g uvs) in
let k =
continuation_elaborator_with_bind (tm_star ctxt frame) e1_typing ctxt_frame_p_typing (nx, x) in
let g' = push_binding g x nx (comp_res c1) in
let ctxt' = tm_star (open_term_nv (comp_post c1) (nx, x)) ctxt in
let veq
: vprop_equiv g' (tm_star (open_term_nv (comp_post c1) (nx, x)) (tm_star ctxt frame))
(tm_star ctxt' frame) = VE_Assoc _ _ _ _ in
let k
: continuation_elaborator
g (tm_star (tm_star ctxt frame) p)
g' (tm_star ctxt' frame) =
k_elab_equiv
#g #g'
#(tm_star (tm_star ctxt frame) p)
#(tm_star (tm_star ctxt frame) p)
#(tm_star (open_term_nv (comp_post c1) (nx, x)) (tm_star ctxt frame))
#(tm_star ctxt' frame)
k (VE_Refl g (tm_star (tm_star ctxt frame) p)) veq in
let ctxt'_frame_typing : tot_typing g' (tm_star ctxt' frame) tm_vprop = RU.magic () in
env_extends_push g x ppname_default (comp_res c1);
(| g', ctxt', ctxt'_frame_typing, k |) | {
"file_name": "lib/steel/pulse/Pulse.Checker.Prover.Base.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 40,
"end_line": 117,
"start_col": 0,
"start_line": 83
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker.Prover.Base
open Pulse.Syntax
open Pulse.Typing
open Pulse.Checker.Base
open Pulse.Typing.Combinators
module RU = Pulse.RuntimeUtils
module T = FStar.Tactics.V2
module PS = Pulse.Checker.Prover.Substs
let rec list_as_vprop' (vp:vprop) (fvps:list vprop)
: Tot vprop (decreases fvps) =
match fvps with
| [] -> vp
| hd::tl -> list_as_vprop' (tm_star vp hd) tl
let rec canon_right_aux (g:env) (vps:list vprop) (f:vprop -> T.Tac bool)
: T.Tac (vps' : list vprop &
fvps : list vprop &
vprop_equiv g (list_as_vprop vps) (list_as_vprop' (list_as_vprop vps') fvps)) =
match vps with
| [] -> (| [], [], VE_Refl _ _ |)
| hd::rest ->
if f hd
then begin
let (| vps', fvps, _ |) = canon_right_aux g rest f in
let v_eq = RU.magic #(vprop_equiv _ _ _) () in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop (hd :: (vps' @ fvps)))
// = list_as_vprop_ctx g [hd] _ rest (vps' @ fvps) (VE_Refl _ _) v_eq
// in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop ((vps'@[hd]) @ fvps))
// = VE_Trans _ _ _ _ v_eq (VE_Sym _ _ _ (vprop_equiv_swap_equiv _ _ _ hd _ (VE_Refl _ _)))
// in
// let v_eq
// : vprop_equiv g (list_as_vprop vps)
// (list_as_vprop (vps'@(hd::fvps)))
// = VE_Trans _ _ _ _ v_eq (VE_Sym _ _ _ (list_as_vprop_assoc _ _ _ _)) in
(| vps', hd :: fvps, v_eq |)
end
else begin
let (| vps', pures, _ |) = canon_right_aux g rest f in
let v_eq = RU.magic #(vprop_equiv _ _ _ ) () in //list_as_vprop_ctx g [hd] _ _ _ (VE_Refl _ _) v_eq in
(| hd::vps', pures, v_eq |)
end
module VP = Pulse.Checker.VPropEquiv
let canon_right (#g:env) (#ctxt:term) (#frame:term)
(ctxt_frame_typing:tot_typing g (tm_star ctxt frame) tm_vprop)
(f:vprop -> T.Tac bool)
: T.Tac (ctxt':term &
tot_typing g (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star ctxt frame) g (tm_star ctxt' frame))
= let (| vps', pures, veq |) = canon_right_aux g (vprop_as_list ctxt) f in
let veq : vprop_equiv g ctxt (list_as_vprop' (list_as_vprop vps') pures)
= RU.magic () in
let veq : vprop_equiv g (tm_star ctxt frame) (tm_star (list_as_vprop' (list_as_vprop vps') pures) frame)
= VE_Ctxt _ _ _ _ _ veq (VE_Refl _ _) in
(| _, VP.vprop_equiv_typing_fwd ctxt_frame_typing veq, k_elab_equiv (k_elab_unit _ _) (VE_Refl _ _) veq |) | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Prover.Substs.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.Prover.Base.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": "VP"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Prover.Substs",
"short_module": "PS"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Prover",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
ctxt: Pulse.Syntax.Base.term ->
frame: Pulse.Syntax.Base.vprop ->
p: Pulse.Syntax.Base.vprop ->
ctxt_frame_p_typing:
Pulse.Typing.tot_typing g
(Pulse.Syntax.Base.tm_star (Pulse.Syntax.Base.tm_star ctxt frame) p)
Pulse.Syntax.Base.tm_vprop ->
nx: Pulse.Syntax.Base.ppname ->
e1: Pulse.Syntax.Base.st_term ->
c1:
Pulse.Syntax.Base.comp
{Pulse.Syntax.Base.stateful_comp c1 /\ Pulse.Syntax.Base.comp_pre c1 == p} ->
e1_typing: Pulse.Typing.st_typing g e1 c1 ->
uvs: Pulse.Typing.Env.env{Pulse.Typing.Env.disjoint uvs g}
-> FStar.Tactics.Effect.Tac
(FStar.Pervasives.dtuple4 (g':
Pulse.Typing.Env.env
{Pulse.Typing.Env.env_extends g' g /\ Pulse.Typing.Env.disjoint uvs g'})
(fun _ -> Pulse.Syntax.Base.term)
(fun g' ctxt' ->
Pulse.Typing.tot_typing g'
(Pulse.Syntax.Base.tm_star ctxt' frame)
Pulse.Syntax.Base.tm_vprop)
(fun g' ctxt' _ ->
Pulse.Checker.Base.continuation_elaborator g
(Pulse.Syntax.Base.tm_star (Pulse.Syntax.Base.tm_star ctxt frame) p)
g'
(Pulse.Syntax.Base.tm_star ctxt' frame))) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Pulse.Syntax.Base.vprop",
"Pulse.Typing.tot_typing",
"Pulse.Syntax.Base.tm_star",
"Pulse.Syntax.Base.tm_vprop",
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.st_term",
"Pulse.Syntax.Base.comp",
"Prims.l_and",
"Prims.b2t",
"Pulse.Syntax.Base.stateful_comp",
"Prims.eq2",
"Pulse.Syntax.Base.comp_pre",
"Pulse.Typing.st_typing",
"Pulse.Typing.Env.disjoint",
"FStar.Pervasives.Mkdtuple4",
"Pulse.Typing.Env.env_extends",
"Pulse.Checker.Base.continuation_elaborator",
"Prims.unit",
"Pulse.Typing.Env.env_extends_push",
"Pulse.Syntax.Base.ppname_default",
"Pulse.Syntax.Base.comp_res",
"Pulse.RuntimeUtils.magic",
"Pulse.Checker.Base.k_elab_equiv",
"Pulse.Syntax.Naming.open_term_nv",
"Pulse.Syntax.Base.comp_post",
"FStar.Pervasives.Native.Mktuple2",
"Pulse.Syntax.Base.var",
"Pulse.Typing.VE_Refl",
"Pulse.Typing.vprop_equiv",
"Pulse.Typing.VE_Assoc",
"FStar.Reflection.Typing.fstar_top_env",
"Pulse.Typing.Env.fstar_env",
"Pulse.Typing.Env.push_binding",
"FStar.Pervasives.dtuple4",
"FStar.Pervasives.Native.snd",
"FStar.Pervasives.Native.fst",
"Pulse.Syntax.Naming.open_term",
"Pulse.Checker.Base.continuation_elaborator_with_bind",
"Prims.l_not",
"FStar.Set.mem",
"Pulse.Typing.Env.dom",
"Pulse.Typing.Env.push_env",
"Pulse.Typing.Env.fresh",
"Pulse.Typing.star_typing_inversion_l"
] | [] | false | true | false | false | false | let elim_one
(#g: env)
(ctxt: term)
(frame p: vprop)
(ctxt_frame_p_typing: tot_typing g (tm_star (tm_star ctxt frame) p) tm_vprop)
(nx: ppname)
(e1: st_term)
(c1: comp{stateful_comp c1 /\ comp_pre c1 == p})
(e1_typing: st_typing g e1 c1)
(uvs: env{disjoint uvs g})
: T.Tac
(g': env{env_extends g' g /\ disjoint uvs g'} &
ctxt': term &
tot_typing g' (tm_star ctxt' frame) tm_vprop &
continuation_elaborator g (tm_star (tm_star ctxt frame) p) g' (tm_star ctxt' frame)) =
| let ctxt_frame_typing = star_typing_inversion_l ctxt_frame_p_typing in
let x = fresh (push_env g uvs) in
let k =
continuation_elaborator_with_bind (tm_star ctxt frame) e1_typing ctxt_frame_p_typing (nx, x)
in
let g' = push_binding g x nx (comp_res c1) in
let ctxt' = tm_star (open_term_nv (comp_post c1) (nx, x)) ctxt in
let veq:vprop_equiv g'
(tm_star (open_term_nv (comp_post c1) (nx, x)) (tm_star ctxt frame))
(tm_star ctxt' frame) =
VE_Assoc _ _ _ _
in
let k:continuation_elaborator g (tm_star (tm_star ctxt frame) p) g' (tm_star ctxt' frame) =
k_elab_equiv #g
#g'
#(tm_star (tm_star ctxt frame) p)
#(tm_star (tm_star ctxt frame) p)
#(tm_star (open_term_nv (comp_post c1) (nx, x)) (tm_star ctxt frame))
#(tm_star ctxt' frame)
k
(VE_Refl g (tm_star (tm_star ctxt frame) p))
veq
in
let ctxt'_frame_typing:tot_typing g' (tm_star ctxt' frame) tm_vprop = RU.magic () in
env_extends_push g x ppname_default (comp_res c1);
(| g', ctxt', ctxt'_frame_typing, k |) | false |
Hacl.Streaming.MD.fst | Hacl.Streaming.MD.alg | val alg : Type0 | let alg = md_alg | {
"file_name": "code/streaming/Hacl.Streaming.MD.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 41,
"start_col": 0,
"start_line": 41
} | module Hacl.Streaming.MD
open FStar.HyperStack.ST
/// This file is poorly named. It contains a generic type class instantiation
/// for the streaming functor for any algorithm that fits within the agile hash
/// infrastructure.
#set-options "--max_fuel 0 --max_ifuel 0 --z3rlimit 100"
module HS = FStar.HyperStack
module B = LowStar.Buffer
module G = FStar.Ghost
module S = FStar.Seq
module U32 = FStar.UInt32
module U64 = FStar.UInt64
module F = Hacl.Streaming.Functor
module ST = FStar.HyperStack.ST
open LowStar.BufferOps
open FStar.Mul
inline_for_extraction noextract
let uint8 = Lib.IntTypes.uint8
inline_for_extraction noextract
let uint32 = Lib.IntTypes.uint32
open Spec.Hash.Definitions
open Hacl.Streaming.Interface
open Hacl.Hash.Definitions
module D = Hacl.Hash.Definitions
module Agile = Spec.Agile.Hash
let _: squash (inversion hash_alg) = allow_inversion hash_alg | {
"checked_file": "/",
"dependencies": [
"Spec.Hash.Lemmas.fsti.checked",
"Spec.Hash.Incremental.fsti.checked",
"Spec.Hash.Definitions.fst.checked",
"Spec.Agile.Hash.fsti.checked",
"prims.fst.checked",
"LowStar.BufferOps.fst.checked",
"LowStar.Buffer.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Streaming.Interface.fsti.checked",
"Hacl.Streaming.Functor.fsti.checked",
"Hacl.Hash.SHA2.fsti.checked",
"Hacl.Hash.SHA1.fsti.checked",
"Hacl.Hash.MD5.fsti.checked",
"Hacl.Hash.Definitions.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Int.Cast.Full.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Streaming.MD.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Agile.Hash",
"short_module": "Agile"
},
{
"abbrev": true,
"full_module": "Hacl.Hash.Definitions",
"short_module": "D"
},
{
"abbrev": false,
"full_module": "Hacl.Hash.Definitions",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming.Interface",
"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": "LowStar.BufferOps",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": true,
"full_module": "Hacl.Streaming.Functor",
"short_module": "F"
},
{
"abbrev": true,
"full_module": "FStar.UInt64",
"short_module": "U64"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "FStar.Ghost",
"short_module": "G"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Streaming",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 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": 100,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Spec.Hash.Definitions.md_alg"
] | [] | false | false | false | true | true | let alg =
| md_alg | false |
|
LowParse.Low.Endianness.fst | LowParse.Low.Endianness.writable_store_pre | val writable_store_pre
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(i j: nat)
(predicate: (Seq.seq byte -> Type))
(h: HS.mem)
: Lemma (requires (writable b i (i + j) h /\ i + j <= B.length b))
(ensures (LE.store_pre b i j predicate h)) | val writable_store_pre
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(i j: nat)
(predicate: (Seq.seq byte -> Type))
(h: HS.mem)
: Lemma (requires (writable b i (i + j) h /\ i + j <= B.length b))
(ensures (LE.store_pre b i j predicate h)) | let writable_store_pre
(#rrel: _)
(#rel: _)
(b: B.mbuffer byte rrel rel)
(i: nat)
(j: nat)
(predicate:Seq.seq byte -> Type)
(h: HS.mem)
: Lemma
(requires (
writable b i (i + j) h /\
i + j <= B.length b
))
(ensures (
LE.store_pre b i j predicate h
))
= let sb = B.as_seq h b in
let len = B.length b in
let phi
(s: Seq.seq byte)
: Lemma
(requires (
Seq.length s == len /\
Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\
Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\
predicate (Seq.slice s i (i + j))
))
(ensures (
rel sb s
))
= assert (sb `Seq.equal` Seq.replace_subseq sb i (i + j) (Seq.slice sb i (i + j)));
assert (s `Seq.equal` Seq.replace_subseq sb i (i + j) (Seq.slice s i (i + j)))
in
Classical.forall_intro (Classical.move_requires phi) | {
"file_name": "src/lowparse/LowParse.Low.Endianness.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 54,
"end_line": 44,
"start_col": 0,
"start_line": 11
} | module LowParse.Low.Endianness
include LowParse.Low.Base
include LowStar.Endianness
module B = LowStar.Buffer
module HS = FStar.HyperStack
module Seq = FStar.Seq
module LE = LowStar.Endianness
module U32 = FStar.UInt32 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowStar.Endianness.fst.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Endianness.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Endianness",
"short_module": "LE"
},
{
"abbrev": true,
"full_module": "FStar.Seq",
"short_module": "Seq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowStar.Endianness",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
b: LowStar.Monotonic.Buffer.mbuffer LowParse.Bytes.byte rrel rel ->
i: Prims.nat ->
j: Prims.nat ->
predicate: (_: FStar.Seq.Base.seq LowParse.Bytes.byte -> Type0) ->
h: FStar.Monotonic.HyperStack.mem
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.writable b i (i + j) h /\ i + j <= LowStar.Monotonic.Buffer.length b)
(ensures LowStar.Endianness.store_pre b i j predicate h) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"LowStar.Monotonic.Buffer.srel",
"LowParse.Bytes.byte",
"LowStar.Monotonic.Buffer.mbuffer",
"Prims.nat",
"FStar.Seq.Base.seq",
"FStar.Monotonic.HyperStack.mem",
"FStar.Classical.forall_intro",
"Prims.l_imp",
"Prims.l_and",
"Prims.eq2",
"FStar.Seq.Base.length",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"Prims.op_Addition",
"FStar.Classical.move_requires",
"Prims.unit",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"Prims._assert",
"FStar.Seq.Properties.replace_subseq",
"LowStar.Monotonic.Buffer.length",
"LowStar.Monotonic.Buffer.as_seq",
"LowParse.Low.Base.writable",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"LowStar.Endianness.store_pre"
] | [] | false | false | true | false | false | let writable_store_pre
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(i j: nat)
(predicate: (Seq.seq byte -> Type))
(h: HS.mem)
: Lemma (requires (writable b i (i + j) h /\ i + j <= B.length b))
(ensures (LE.store_pre b i j predicate h)) =
| let sb = B.as_seq h b in
let len = B.length b in
let phi (s: Seq.seq byte)
: Lemma
(requires
(Seq.length s == len /\ Seq.equal (Seq.slice s 0 i) (Seq.slice sb 0 i) /\
Seq.equal (Seq.slice s (i + j) len) (Seq.slice sb (i + j) len) /\
predicate (Seq.slice s i (i + j)))) (ensures (rel sb s)) =
assert (sb `Seq.equal` (Seq.replace_subseq sb i (i + j) (Seq.slice sb i (i + j))));
assert (s `Seq.equal` (Seq.replace_subseq sb i (i + j) (Seq.slice s i (i + j))))
in
Classical.forall_intro (Classical.move_requires phi) | false |
Pulse.Checker.fst | Pulse.Checker.transform_to_unary_intro_exists | val transform_to_unary_intro_exists (g: env) (t: term) (ws: list term) : T.Tac st_term | val transform_to_unary_intro_exists (g: env) (t: term) (ws: list term) : T.Tac st_term | let rec transform_to_unary_intro_exists (g:env) (t:term) (ws:list term)
: T.Tac st_term =
match ws with
| [] -> fail g (Some t.range) "intro exists with empty witnesses"
| [w] ->
if Tm_ExistsSL? t.t
then wtag (Some STT_Ghost) (Tm_IntroExists {p=t;witnesses=[w]})
else fail g (Some t.range) "intro exists with non-existential"
| w::ws ->
match t.t with
| Tm_ExistsSL u b body ->
let body = subst_term body [ DT 0 w ] in
let st = transform_to_unary_intro_exists g body ws in
// w is the witness
let intro = wtag None (Tm_IntroExists {p=t;witnesses=[w]}) in
wtag None
(Tm_Bind {binder=null_binder tm_unit;
head=st;
body= intro})
| _ -> fail g (Some t.range) "intro exists with non-existential" | {
"file_name": "lib/steel/pulse/Pulse.Checker.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 68,
"end_line": 136,
"start_col": 0,
"start_line": 115
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module T = FStar.Tactics.V2
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Reflection.Util
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Checker.Pure
open Pulse.Checker.Bind
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Base
module P = Pulse.Syntax.Printer
module RTB = FStar.Tactics.Builtins
module FV = Pulse.Typing.FV
module RU = Pulse.RuntimeUtils
module Metatheory = Pulse.Typing.Metatheory
module Abs = Pulse.Checker.Abs
module If = Pulse.Checker.If
module Bind = Pulse.Checker.Bind
module Match = Pulse.Checker.Match
module WithLocal = Pulse.Checker.WithLocal
module WithLocalArray = Pulse.Checker.WithLocalArray
module While = Pulse.Checker.While
module STApp = Pulse.Checker.STApp
module Exists = Pulse.Checker.Exists
module Par = Pulse.Checker.Par
module Admit = Pulse.Checker.Admit
module Return = Pulse.Checker.Return
module Rewrite = Pulse.Checker.Rewrite
module WithInv = Pulse.Checker.WithInv
let terms_to_string (t:list term)
: T.Tac string
= String.concat "\n" (T.map Pulse.Syntax.Printer.term_to_string t)
let default_binder_annot = mk_binder_ppname tm_unknown ppname_default
let rec gen_names_for_unknowns (g:env) (t:term) (ws:list term)
: T.Tac (list (nvar & term) & // new names with their types
term & // opened vprop
list term) // new list of witnesses with _ replaced with corresponding new names
= match ws with
| [] -> [], t, []
| w::ws ->
match t.t with
| Tm_ExistsSL _ b body ->
let xopt, w, g =
match w.t with
| Tm_Unknown ->
let x = fresh g in
Some x,
tm_var {nm_index=x;nm_ppname=b.binder_ppname},
push_binding g x b.binder_ppname b.binder_ty
| _ -> None, w, g in
let t : term = open_term' body w 0 in
let new_names, t, ws = gen_names_for_unknowns g t ws in
(match xopt with
| Some x ->
((b.binder_ppname, x), b.binder_ty)::new_names,
t,
w::ws
| None -> new_names, t, w::ws)
| _ -> fail g (Some t.range) "intro exists with non-existential"
let instantiate_unknown_witnesses (g:env) (t:st_term { Tm_IntroExists? t.term })
: T.Tac (option st_term) =
let Tm_IntroExists { p; witnesses=ws } = t.term in
let new_names, opened_p, new_ws = gen_names_for_unknowns g p ws in
match new_names with
| [] -> None
| _ ->
let e2 = {t with term=Tm_IntroExists { p; witnesses=new_ws }} in
let e1 =
let hint_type = ASSERT { p = opened_p } in
let binders = [] in
{term=Tm_ProofHintWithBinders { hint_type;binders;t=e2 }; range=t.range; effect_tag=as_effect_hint STT_Ghost } in
let t =
L.fold_right
(fun new_name (e:st_term { Tm_ProofHintWithBinders? e.term }) ->
let (ppname, x), ty = new_name in
let e = close_st_term' e x 0 in
match e.term with
| Tm_ProofHintWithBinders {hint_type;binders;t} ->
let new_binder = mk_binder_ppname ty ppname in
let t' = Tm_ProofHintWithBinders {hint_type;binders=new_binder::binders;t} in
{e with term=t'})
new_names
e1 in
Some t | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.FV.fsti.checked",
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Checker.WithLocalArray.fsti.checked",
"Pulse.Checker.WithLocal.fsti.checked",
"Pulse.Checker.WithInv.fsti.checked",
"Pulse.Checker.While.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Unreachable.fsti.checked",
"Pulse.Checker.STApp.fsti.checked",
"Pulse.Checker.Rewrite.fsti.checked",
"Pulse.Checker.Return.fsti.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Par.fsti.checked",
"Pulse.Checker.Match.fsti.checked",
"Pulse.Checker.IntroPure.fsti.checked",
"Pulse.Checker.If.fsti.checked",
"Pulse.Checker.Exists.fsti.checked",
"Pulse.Checker.Bind.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"Pulse.Checker.AssertWithBinders.fsti.checked",
"Pulse.Checker.Admit.fsti.checked",
"Pulse.Checker.Abs.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Builtins.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.WithInv",
"short_module": "WithInv"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Rewrite",
"short_module": "Rewrite"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Return",
"short_module": "Return"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Admit",
"short_module": "Admit"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Par",
"short_module": "Par"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Exists",
"short_module": "Exists"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.STApp",
"short_module": "STApp"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.While",
"short_module": "While"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.WithLocalArray",
"short_module": "WithLocalArray"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.WithLocal",
"short_module": "WithLocal"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Match",
"short_module": "Match"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Bind",
"short_module": "Bind"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.If",
"short_module": "If"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Abs",
"short_module": "Abs"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.FV",
"short_module": "FV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Bind",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> t: Pulse.Syntax.Base.term -> ws: Prims.list Pulse.Syntax.Base.term
-> FStar.Tactics.Effect.Tac Pulse.Syntax.Base.st_term | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.term",
"Prims.list",
"Pulse.Typing.Env.fail",
"Pulse.Syntax.Base.st_term",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.range",
"Pulse.Syntax.Base.__proj__Mkterm__item__range",
"Pulse.Syntax.Base.uu___is_Tm_ExistsSL",
"Pulse.Syntax.Base.__proj__Mkterm__item__t",
"Pulse.Typing.wtag",
"Pulse.Syntax.Base.ctag",
"Pulse.Syntax.Base.STT_Ghost",
"Pulse.Syntax.Base.Tm_IntroExists",
"Pulse.Syntax.Base.Mkst_term'__Tm_IntroExists__payload",
"Prims.Cons",
"Prims.Nil",
"Prims.bool",
"Pulse.Syntax.Base.universe",
"Pulse.Syntax.Base.binder",
"FStar.Pervasives.Native.None",
"Pulse.Syntax.Base.Tm_Bind",
"Pulse.Syntax.Base.Mkst_term'__Tm_Bind__payload",
"Pulse.Syntax.Base.null_binder",
"Pulse.Typing.tm_unit",
"Pulse.Checker.transform_to_unary_intro_exists",
"Pulse.Syntax.Naming.subst_term",
"Pulse.Syntax.Naming.subst_elt",
"Pulse.Syntax.Naming.DT",
"Pulse.Syntax.Base.term'"
] | [
"recursion"
] | false | true | false | false | false | let rec transform_to_unary_intro_exists (g: env) (t: term) (ws: list term) : T.Tac st_term =
| match ws with
| [] -> fail g (Some t.range) "intro exists with empty witnesses"
| [w] ->
if Tm_ExistsSL? t.t
then wtag (Some STT_Ghost) (Tm_IntroExists ({ p = t; witnesses = [w] }))
else fail g (Some t.range) "intro exists with non-existential"
| w :: ws ->
match t.t with
| Tm_ExistsSL u b body ->
let body = subst_term body [DT 0 w] in
let st = transform_to_unary_intro_exists g body ws in
let intro = wtag None (Tm_IntroExists ({ p = t; witnesses = [w] })) in
wtag None (Tm_Bind ({ binder = null_binder tm_unit; head = st; body = intro }))
| _ -> fail g (Some t.range) "intro exists with non-existential" | false |
Pulse.Checker.fst | Pulse.Checker.instantiate_unknown_witnesses | val instantiate_unknown_witnesses (g: env) (t: st_term{Tm_IntroExists? t.term})
: T.Tac (option st_term) | val instantiate_unknown_witnesses (g: env) (t: st_term{Tm_IntroExists? t.term})
: T.Tac (option st_term) | let instantiate_unknown_witnesses (g:env) (t:st_term { Tm_IntroExists? t.term })
: T.Tac (option st_term) =
let Tm_IntroExists { p; witnesses=ws } = t.term in
let new_names, opened_p, new_ws = gen_names_for_unknowns g p ws in
match new_names with
| [] -> None
| _ ->
let e2 = {t with term=Tm_IntroExists { p; witnesses=new_ws }} in
let e1 =
let hint_type = ASSERT { p = opened_p } in
let binders = [] in
{term=Tm_ProofHintWithBinders { hint_type;binders;t=e2 }; range=t.range; effect_tag=as_effect_hint STT_Ghost } in
let t =
L.fold_right
(fun new_name (e:st_term { Tm_ProofHintWithBinders? e.term }) ->
let (ppname, x), ty = new_name in
let e = close_st_term' e x 0 in
match e.term with
| Tm_ProofHintWithBinders {hint_type;binders;t} ->
let new_binder = mk_binder_ppname ty ppname in
let t' = Tm_ProofHintWithBinders {hint_type;binders=new_binder::binders;t} in
{e with term=t'})
new_names
e1 in
Some t | {
"file_name": "lib/steel/pulse/Pulse.Checker.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 10,
"end_line": 113,
"start_col": 0,
"start_line": 86
} | (*
Copyright 2023 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Pulse.Checker
module RT = FStar.Reflection.Typing
module R = FStar.Reflection.V2
module L = FStar.List.Tot
module T = FStar.Tactics.V2
open FStar.List.Tot
open Pulse.Syntax
open Pulse.Reflection.Util
open Pulse.Typing
open Pulse.Typing.Combinators
open Pulse.Checker.Pure
open Pulse.Checker.Bind
open Pulse.Checker.VPropEquiv
open Pulse.Checker.Base
module P = Pulse.Syntax.Printer
module RTB = FStar.Tactics.Builtins
module FV = Pulse.Typing.FV
module RU = Pulse.RuntimeUtils
module Metatheory = Pulse.Typing.Metatheory
module Abs = Pulse.Checker.Abs
module If = Pulse.Checker.If
module Bind = Pulse.Checker.Bind
module Match = Pulse.Checker.Match
module WithLocal = Pulse.Checker.WithLocal
module WithLocalArray = Pulse.Checker.WithLocalArray
module While = Pulse.Checker.While
module STApp = Pulse.Checker.STApp
module Exists = Pulse.Checker.Exists
module Par = Pulse.Checker.Par
module Admit = Pulse.Checker.Admit
module Return = Pulse.Checker.Return
module Rewrite = Pulse.Checker.Rewrite
module WithInv = Pulse.Checker.WithInv
let terms_to_string (t:list term)
: T.Tac string
= String.concat "\n" (T.map Pulse.Syntax.Printer.term_to_string t)
let default_binder_annot = mk_binder_ppname tm_unknown ppname_default
let rec gen_names_for_unknowns (g:env) (t:term) (ws:list term)
: T.Tac (list (nvar & term) & // new names with their types
term & // opened vprop
list term) // new list of witnesses with _ replaced with corresponding new names
= match ws with
| [] -> [], t, []
| w::ws ->
match t.t with
| Tm_ExistsSL _ b body ->
let xopt, w, g =
match w.t with
| Tm_Unknown ->
let x = fresh g in
Some x,
tm_var {nm_index=x;nm_ppname=b.binder_ppname},
push_binding g x b.binder_ppname b.binder_ty
| _ -> None, w, g in
let t : term = open_term' body w 0 in
let new_names, t, ws = gen_names_for_unknowns g t ws in
(match xopt with
| Some x ->
((b.binder_ppname, x), b.binder_ty)::new_names,
t,
w::ws
| None -> new_names, t, w::ws)
| _ -> fail g (Some t.range) "intro exists with non-existential" | {
"checked_file": "/",
"dependencies": [
"Pulse.Typing.Metatheory.fsti.checked",
"Pulse.Typing.FV.fsti.checked",
"Pulse.Typing.Env.fsti.checked",
"Pulse.Typing.Combinators.fsti.checked",
"Pulse.Typing.fst.checked",
"Pulse.Syntax.Printer.fsti.checked",
"Pulse.Syntax.fst.checked",
"Pulse.RuntimeUtils.fsti.checked",
"Pulse.Reflection.Util.fst.checked",
"Pulse.Checker.WithLocalArray.fsti.checked",
"Pulse.Checker.WithLocal.fsti.checked",
"Pulse.Checker.WithInv.fsti.checked",
"Pulse.Checker.While.fsti.checked",
"Pulse.Checker.VPropEquiv.fsti.checked",
"Pulse.Checker.Unreachable.fsti.checked",
"Pulse.Checker.STApp.fsti.checked",
"Pulse.Checker.Rewrite.fsti.checked",
"Pulse.Checker.Return.fsti.checked",
"Pulse.Checker.Pure.fsti.checked",
"Pulse.Checker.Prover.fsti.checked",
"Pulse.Checker.Par.fsti.checked",
"Pulse.Checker.Match.fsti.checked",
"Pulse.Checker.IntroPure.fsti.checked",
"Pulse.Checker.If.fsti.checked",
"Pulse.Checker.Exists.fsti.checked",
"Pulse.Checker.Bind.fsti.checked",
"Pulse.Checker.Base.fsti.checked",
"Pulse.Checker.AssertWithBinders.fsti.checked",
"Pulse.Checker.Admit.fsti.checked",
"Pulse.Checker.Abs.fsti.checked",
"prims.fst.checked",
"FStar.Tactics.V2.fst.checked",
"FStar.Tactics.Builtins.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Reflection.V2.fst.checked",
"FStar.Reflection.Typing.fsti.checked",
"FStar.Printf.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked"
],
"interface_file": true,
"source_file": "Pulse.Checker.fst"
} | [
{
"abbrev": true,
"full_module": "Pulse.Checker.WithInv",
"short_module": "WithInv"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Rewrite",
"short_module": "Rewrite"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Return",
"short_module": "Return"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Admit",
"short_module": "Admit"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Par",
"short_module": "Par"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Exists",
"short_module": "Exists"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.STApp",
"short_module": "STApp"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.While",
"short_module": "While"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.WithLocalArray",
"short_module": "WithLocalArray"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.WithLocal",
"short_module": "WithLocal"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Match",
"short_module": "Match"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Bind",
"short_module": "Bind"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.If",
"short_module": "If"
},
{
"abbrev": true,
"full_module": "Pulse.Checker.Abs",
"short_module": "Abs"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.Metatheory",
"short_module": "Metatheory"
},
{
"abbrev": true,
"full_module": "Pulse.RuntimeUtils",
"short_module": "RU"
},
{
"abbrev": true,
"full_module": "Pulse.Typing.FV",
"short_module": "FV"
},
{
"abbrev": true,
"full_module": "FStar.Tactics.Builtins",
"short_module": "RTB"
},
{
"abbrev": true,
"full_module": "Pulse.Syntax.Printer",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.VPropEquiv",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Bind",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Reflection.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse.Checker.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Typing",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Elaborate.Pure",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse.Syntax",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.List.Tot",
"short_module": null
},
{
"abbrev": true,
"full_module": "FStar.Tactics.V2",
"short_module": "T"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.V2",
"short_module": "R"
},
{
"abbrev": true,
"full_module": "FStar.Reflection.Typing",
"short_module": "RT"
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "Pulse",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | g: Pulse.Typing.Env.env -> t: Pulse.Syntax.Base.st_term{Tm_IntroExists? (Mkst_term?.term t)}
-> FStar.Tactics.Effect.Tac (FStar.Pervasives.Native.option Pulse.Syntax.Base.st_term) | FStar.Tactics.Effect.Tac | [] | [] | [
"Pulse.Typing.Env.env",
"Pulse.Syntax.Base.st_term",
"Prims.b2t",
"Pulse.Syntax.Base.uu___is_Tm_IntroExists",
"Pulse.Syntax.Base.__proj__Mkst_term__item__term",
"Pulse.Syntax.Base.vprop",
"Prims.list",
"Pulse.Syntax.Base.term",
"FStar.Pervasives.Native.tuple2",
"Pulse.Syntax.Base.nvar",
"FStar.Pervasives.Native.None",
"FStar.Pervasives.Native.Some",
"Pulse.Syntax.Base.uu___is_Tm_ProofHintWithBinders",
"FStar.List.Tot.Base.fold_right",
"Pulse.Syntax.Base.ppname",
"Pulse.Syntax.Base.var",
"Pulse.Syntax.Base.proof_hint_type",
"Pulse.Syntax.Base.binder",
"Pulse.Syntax.Base.Mkst_term",
"Pulse.Syntax.Base.__proj__Mkst_term__item__range",
"Pulse.Syntax.Base.__proj__Mkst_term__item__effect_tag",
"Pulse.Syntax.Base.st_term'",
"Pulse.Syntax.Base.Tm_ProofHintWithBinders",
"Pulse.Syntax.Base.Mkst_term'__Tm_ProofHintWithBinders__payload",
"Prims.Cons",
"Pulse.Syntax.Base.mk_binder_ppname",
"Pulse.Syntax.Naming.close_st_term'",
"Pulse.Syntax.Base.as_effect_hint",
"Pulse.Syntax.Base.STT_Ghost",
"Prims.Nil",
"Pulse.Syntax.Base.ASSERT",
"Pulse.Syntax.Base.Mkproof_hint_type__ASSERT__payload",
"Pulse.Syntax.Base.Tm_IntroExists",
"Pulse.Syntax.Base.Mkst_term'__Tm_IntroExists__payload",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple3",
"Pulse.Checker.gen_names_for_unknowns"
] | [] | false | true | false | false | false | let instantiate_unknown_witnesses (g: env) (t: st_term{Tm_IntroExists? t.term})
: T.Tac (option st_term) =
| let Tm_IntroExists { p = p ; witnesses = ws } = t.term in
let new_names, opened_p, new_ws = gen_names_for_unknowns g p ws in
match new_names with
| [] -> None
| _ ->
let e2 = { t with term = Tm_IntroExists ({ p = p; witnesses = new_ws }) } in
let e1 =
let hint_type = ASSERT ({ p = opened_p }) in
let binders = [] in
{
term = Tm_ProofHintWithBinders ({ hint_type = hint_type; binders = binders; t = e2 });
range = t.range;
effect_tag = as_effect_hint STT_Ghost
}
in
let t =
L.fold_right (fun new_name (e: st_term{Tm_ProofHintWithBinders? e.term}) ->
let (ppname, x), ty = new_name in
let e = close_st_term' e x 0 in
match e.term with
| Tm_ProofHintWithBinders { hint_type = hint_type ; binders = binders ; t = t } ->
let new_binder = mk_binder_ppname ty ppname in
let t' =
Tm_ProofHintWithBinders
({ hint_type = hint_type; binders = new_binder :: binders; t = t })
in
{ e with term = t' })
new_names
e1
in
Some t | false |
EverParse3d.Kinds.fst | EverParse3d.Kinds.parser_kind_prop | val parser_kind_prop (nz: bool) (wk: weak_kind) (k: LP.parser_kind) : Tot prop | val parser_kind_prop (nz: bool) (wk: weak_kind) (k: LP.parser_kind) : Tot prop | let parser_kind_prop
(nz: bool)
(wk: weak_kind)
(k: LP.parser_kind)
: Tot prop
= (nz ==> (k.LP.parser_kind_low > 0)) /\
begin match wk with
| WeakKindStrongPrefix -> k.LP.parser_kind_subkind == Some LP.ParserStrong
| WeakKindConsumesAll -> k.LP.parser_kind_subkind == Some LP.ParserConsumesAll
| _ -> True
end | {
"file_name": "src/3d/prelude/EverParse3d.Kinds.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 5,
"end_line": 34,
"start_col": 0,
"start_line": 24
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Kinds
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
////////////////////////////////////////////////////////////////////////////////
// Parsers
//////////////////////////////////////////////////////////////////////////////// | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.Bytes.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Kinds.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | nz: Prims.bool -> wk: EverParse3d.Kinds.weak_kind -> k: LowParse.Spec.Base.parser_kind -> Prims.prop | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"EverParse3d.Kinds.weak_kind",
"LowParse.Spec.Base.parser_kind",
"Prims.l_and",
"Prims.l_imp",
"Prims.b2t",
"Prims.op_GreaterThan",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Spec.Base.ParserConsumesAll",
"Prims.l_True",
"Prims.logical",
"Prims.prop"
] | [] | false | false | false | true | true | let parser_kind_prop (nz: bool) (wk: weak_kind) (k: LP.parser_kind) : Tot prop =
| (nz ==> (k.LP.parser_kind_low > 0)) /\
(match wk with
| WeakKindStrongPrefix -> k.LP.parser_kind_subkind == Some LP.ParserStrong
| WeakKindConsumesAll -> k.LP.parser_kind_subkind == Some LP.ParserConsumesAll
| _ -> True) | false |
EverParse3d.Kinds.fst | EverParse3d.Kinds.parser_kind | val parser_kind (nz:bool) (wk: weak_kind) : Type0 | val parser_kind (nz:bool) (wk: weak_kind) : Type0 | let parser_kind (nz:bool) (wk: weak_kind) =
k:LP.parser_kind { parser_kind_prop nz wk k } | {
"file_name": "src/3d/prelude/EverParse3d.Kinds.fst",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 47,
"end_line": 39,
"start_col": 0,
"start_line": 38
} | (*
Copyright 2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module EverParse3d.Kinds
module LP = LowParse.Spec.Base
module LPC = LowParse.Spec.Combinators
////////////////////////////////////////////////////////////////////////////////
// Parsers
////////////////////////////////////////////////////////////////////////////////
let parser_kind_prop
(nz: bool)
(wk: weak_kind)
(k: LP.parser_kind)
: Tot prop
= (nz ==> (k.LP.parser_kind_low > 0)) /\
begin match wk with
| WeakKindStrongPrefix -> k.LP.parser_kind_subkind == Some LP.ParserStrong
| WeakKindConsumesAll -> k.LP.parser_kind_subkind == Some LP.ParserConsumesAll
| _ -> True
end
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.List.fsti.checked",
"LowParse.Spec.Int.fsti.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Spec.Bytes.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.Spec.Base.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": true,
"source_file": "EverParse3d.Kinds.fst"
} | [
{
"abbrev": true,
"full_module": "LowParse.Spec.Combinators",
"short_module": "LPC"
},
{
"abbrev": true,
"full_module": "LowParse.Spec.Base",
"short_module": "LP"
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "EverParse3d",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 2,
"max_fuel": 0,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [
"smt.qi.eager_threshold=10"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | nz: Prims.bool -> wk: EverParse3d.Kinds.weak_kind -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.bool",
"EverParse3d.Kinds.weak_kind",
"LowParse.Spec.Base.parser_kind",
"EverParse3d.Kinds.parser_kind_prop"
] | [] | false | false | false | true | true | let parser_kind (nz: bool) (wk: weak_kind) =
| k: LP.parser_kind{parser_kind_prop nz wk k} | false |
Hacl.Impl.Poly1305.Bignum128.fst | Hacl.Impl.Poly1305.Bignum128.mod_add128_lemma | val mod_add128_lemma: a:(uint64 & uint64) -> b:(uint64 & uint64) ->
Lemma (let (a0, a1) = a in let (b0, b1) = b in
let r0 = a0 +. b0 in let r1 = a1 +. b1 in
let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
let r1 = r1 +. c in
v r1 * pow2 64 + v r0 == ((v a1 + v b1) * pow2 64 + v a0 + v b0) % pow2 128) | val mod_add128_lemma: a:(uint64 & uint64) -> b:(uint64 & uint64) ->
Lemma (let (a0, a1) = a in let (b0, b1) = b in
let r0 = a0 +. b0 in let r1 = a1 +. b1 in
let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
let r1 = r1 +. c in
v r1 * pow2 64 + v r0 == ((v a1 + v b1) * pow2 64 + v a0 + v b0) % pow2 128) | let mod_add128_lemma a b =
let (a0, a1) = a in
let (b0, b1) = b in
let r0 = a0 +. b0 in
let r1 = a1 +. b1 in
let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
constant_time_carry_ok r0 b0;
assert (v c == (if v r0 < v b0 then 1 else 0));
assert (v c == (v a0 + v b0) / pow2 64);
let r2 = r1 +. c in
calc (==) {
v r2 * pow2 64 + v r0;
(==) { }
((v a1 + v b1) % pow2 64 + (v a0 + v b0) / pow2 64) % pow2 64 * pow2 64 + (v a0 + v b0) % pow2 64;
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 ((v a1 + v b1) % pow2 64 + (v a0 + v b0) / pow2 64) 128 64 }
((v a1 + v b1) % pow2 64 + (v a0 + v b0) / pow2 64) * pow2 64 % pow2 128 + (v a0 + v b0) % pow2 64;
(==) { }
((v a1 + v b1) % pow2 64 * pow2 64 + (v a0 + v b0) / pow2 64 * pow2 64) % pow2 128 + (v a0 + v b0) % pow2 64;
(==) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v a1 + v b1) 128 64 }
((v a1 + v b1) * pow2 64 % pow2 128 + (v a0 + v b0) / pow2 64 * pow2 64) % pow2 128 + (v a0 + v b0) % pow2 64;
(==) { Math.Lemmas.lemma_mod_plus_distr_l ((v a1 + v b1) * pow2 64) ((v a0 + v b0) / pow2 64 * pow2 64) (pow2 128) }
((v a1 + v b1) * pow2 64 + (v a0 + v b0) / pow2 64 * pow2 64) % pow2 128 + (v a0 + v b0) % pow2 64;
(==) { Math.Lemmas.modulo_lemma ((v a0 + v b0) % pow2 64) (pow2 128) }
((v a1 + v b1) * pow2 64 + (v a0 + v b0) / pow2 64 * pow2 64) % pow2 128 + ((v a0 + v b0) % pow2 64) % pow2 128;
};
assert (v r2 * pow2 64 + v r0 ==
((v a1 + v b1) * pow2 64 + (v a0 + v b0) / pow2 64 * pow2 64) % pow2 128 + ((v a0 + v b0) % pow2 64) % pow2 128);
assert (v r2 * pow2 64 + v r0 < pow2 128);
add_mod_small ((v a1 + v b1) * pow2 64 + (v a0 + v b0) / pow2 64 * pow2 64) ((v a0 + v b0) % pow2 64) (pow2 128);
Math.Lemmas.euclidean_division_definition (v a0 + v b0) (pow2 64);
assert (v r2 * pow2 64 + v r0 == ((v a1 + v b1) * pow2 64 + v a0 + v b0) % pow2 128) | {
"file_name": "code/poly1305/Hacl.Impl.Poly1305.Bignum128.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 86,
"end_line": 114,
"start_col": 0,
"start_line": 83
} | module Hacl.Impl.Poly1305.Bignum128
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Lib.ByteBuffer
open Hacl.Impl.Poly1305.Lemmas
module ST = FStar.HyperStack.ST
module LSeq = Lib.Sequence
module BSeq = Lib.ByteSequence
friend FStar.UInt128
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let uints64_from_bytes_le b =
let h0 = ST.get () in
let lo = uint_from_bytes_le #U64 (sub b 0ul 8ul) in
let hi = uint_from_bytes_le #U64 (sub b 8ul 8ul) in
uint_from_bytes_le_lemma (as_seq h0 b);
lo, hi
let uints64_to_bytes_le b r0 r1 =
let h0 = ST.get () in
update_sub_f h0 b 0ul 8ul
(fun h -> BSeq.uint_to_bytes_le #U64 r0)
(fun _ -> uint_to_bytes_le (sub b 0ul 8ul) r0);
let h1 = ST.get () in
update_sub_f h1 b 8ul 8ul
(fun h -> BSeq.uint_to_bytes_le #U64 r1)
(fun _ -> uint_to_bytes_le (sub b 8ul 8ul) r1);
//uint_to_bytes_le (sub b 0ul 8ul) r0;
//uint_to_bytes_le (sub b 8ul 8ul) r1;
let h2 = ST.get () in
uints64_to_bytes_le_lemma r0 r1;
LSeq.eq_intro (LSeq.sub (as_seq h2 b) 0 8) (BSeq.uint_to_bytes_le #U64 r0);
LSeq.lemma_concat2
8 (BSeq.uint_to_bytes_le #U64 r0)
8 (BSeq.uint_to_bytes_le #U64 r1) (as_seq h2 b)
val constant_time_carry_ok: r0:uint64 -> b0:uint64 ->
Lemma (let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
v c == (if v r0 < v b0 then 1 else 0))
let constant_time_carry_ok r0 b0 =
let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
let r0' = Lib.RawIntTypes.u64_to_UInt64 r0 in
let b0' = Lib.RawIntTypes.u64_to_UInt64 b0 in
let c' = FStar.UInt128.constant_time_carry r0' b0' in
logxor_spec r0 b0;
logxor_spec (r0 -. b0) b0;
logor_spec (r0 ^. b0) ((r0 -. b0) ^. b0);
logxor_spec r0 ((r0 ^. b0) |. ((r0 -. b0) ^. b0));
assert (v c' == v c);
FStar.UInt128.constant_time_carry_ok r0' b0'
val add_mod_small: a:nat -> b:nat -> n:pos -> Lemma
(requires a % n + b % n < n)
(ensures a % n + b % n == (a + b) % n)
let add_mod_small a b n =
FStar.Math.Lemmas.modulo_lemma (a % n + b % n) n;
assert (a % n + b % n == (a % n + b % n) % n);
FStar.Math.Lemmas.lemma_mod_plus_distr_l a (b % n) n;
FStar.Math.Lemmas.lemma_mod_plus_distr_r a b n
val mod_add128_lemma: a:(uint64 & uint64) -> b:(uint64 & uint64) ->
Lemma (let (a0, a1) = a in let (b0, b1) = b in
let r0 = a0 +. b0 in let r1 = a1 +. b1 in
let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
let r1 = r1 +. c in
v r1 * pow2 64 + v r0 == ((v a1 + v b1) * pow2 64 + v a0 + v b0) % pow2 128) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.RawIntTypes.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.ByteSequence.fsti.checked",
"Lib.ByteBuffer.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Impl.Poly1305.Lemmas.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt128.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.All.fst.checked",
"FStar.HyperStack.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": true,
"source_file": "Hacl.Impl.Poly1305.Bignum128.fst"
} | [
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"abbrev": true,
"full_module": "Lib.Sequence",
"short_module": "LSeq"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305.Lemmas",
"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.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.ByteSequence",
"short_module": "BSeq"
},
{
"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.All",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: (Lib.IntTypes.uint64 * Lib.IntTypes.uint64) -> b: (Lib.IntTypes.uint64 * Lib.IntTypes.uint64)
-> FStar.Pervasives.Lemma
(ensures
(let _ = a in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ a0 a1 = _ in
let _ = b in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ b0 b1 = _ in
let r0 = a0 +. b0 in
let r1 = a1 +. b1 in
let c = r0 ^. (r0 ^. b0 |. r0 -. b0 ^. b0) >>. 63ul in
let r1 = r1 +. c in
Lib.IntTypes.v r1 * Prims.pow2 64 + Lib.IntTypes.v r0 ==
((Lib.IntTypes.v a1 + Lib.IntTypes.v b1) * Prims.pow2 64 + Lib.IntTypes.v a0 +
Lib.IntTypes.v b0) %
Prims.pow2 128)
<:
Type0)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.uint64",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Prims.op_Modulus",
"Prims.unit",
"FStar.Math.Lemmas.euclidean_division_definition",
"Hacl.Impl.Poly1305.Bignum128.add_mod_small",
"Prims.op_Division",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Calc.calc_finish",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Prims.squash",
"FStar.Math.Lemmas.pow2_multiplication_modulo_lemma_2",
"FStar.Math.Lemmas.lemma_mod_plus_distr_l",
"FStar.Math.Lemmas.modulo_lemma",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Plus_Dot",
"Prims.bool",
"Hacl.Impl.Poly1305.Bignum128.constant_time_carry_ok",
"Lib.IntTypes.op_Greater_Greater_Dot",
"Lib.IntTypes.op_Hat_Dot",
"Lib.IntTypes.op_Bar_Dot",
"Lib.IntTypes.op_Subtraction_Dot",
"FStar.UInt32.__uint_to_t"
] | [] | false | false | true | false | false | let mod_add128_lemma a b =
| let a0, a1 = a in
let b0, b1 = b in
let r0 = a0 +. b0 in
let r1 = a1 +. b1 in
let c = r0 ^. ((r0 ^. b0) |. ((r0 -. b0) ^. b0)) >>. 63ul in
constant_time_carry_ok r0 b0;
assert (v c == (if v r0 < v b0 then 1 else 0));
assert (v c == (v a0 + v b0) / pow2 64);
let r2 = r1 +. c in
calc ( == ) {
v r2 * pow2 64 + v r0;
( == ) { () }
(((v a1 + v b1) % pow2 64 + (v a0 + v b0) / pow2 64) % pow2 64) * pow2 64 +
(v a0 + v b0) % pow2 64;
( == ) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 ((v a1 + v b1) % pow2 64 +
(v a0 + v b0) / pow2 64)
128
64 }
((v a1 + v b1) % pow2 64 + (v a0 + v b0) / pow2 64) * pow2 64 % pow2 128 + (v a0 + v b0) % pow2 64;
( == ) { () }
(((v a1 + v b1) % pow2 64) * pow2 64 + ((v a0 + v b0) / pow2 64) * pow2 64) % pow2 128 +
(v a0 + v b0) % pow2 64;
( == ) { Math.Lemmas.pow2_multiplication_modulo_lemma_2 (v a1 + v b1) 128 64 }
((v a1 + v b1) * pow2 64 % pow2 128 + ((v a0 + v b0) / pow2 64) * pow2 64) % pow2 128 +
(v a0 + v b0) % pow2 64;
( == ) { Math.Lemmas.lemma_mod_plus_distr_l ((v a1 + v b1) * pow2 64)
(((v a0 + v b0) / pow2 64) * pow2 64)
(pow2 128) }
((v a1 + v b1) * pow2 64 + ((v a0 + v b0) / pow2 64) * pow2 64) % pow2 128 +
(v a0 + v b0) % pow2 64;
( == ) { Math.Lemmas.modulo_lemma ((v a0 + v b0) % pow2 64) (pow2 128) }
((v a1 + v b1) * pow2 64 + ((v a0 + v b0) / pow2 64) * pow2 64) % pow2 128 +
((v a0 + v b0) % pow2 64) % pow2 128;
};
assert (v r2 * pow2 64 + v r0 ==
((v a1 + v b1) * pow2 64 + ((v a0 + v b0) / pow2 64) * pow2 64) % pow2 128 +
((v a0 + v b0) % pow2 64) % pow2 128);
assert (v r2 * pow2 64 + v r0 < pow2 128);
add_mod_small ((v a1 + v b1) * pow2 64 + ((v a0 + v b0) / pow2 64) * pow2 64)
((v a0 + v b0) % pow2 64)
(pow2 128);
Math.Lemmas.euclidean_division_definition (v a0 + v b0) (pow2 64);
assert (v r2 * pow2 64 + v r0 == ((v a1 + v b1) * pow2 64 + v a0 + v b0) % pow2 128) | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.