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.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.sub1 | val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin) | val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin) | let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 50,
"start_col": 0,
"start_line": 47
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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.Curve25519.Field64.Core.felem -> cin: Lib.IntTypes.uint64
-> Prims.Pure (Lib.IntTypes.uint64 * Hacl.Spec.Curve25519.Field64.Core.felem) | Prims.Pure | [] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Hacl.Spec.Bignum.bn_sub1_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_sub1"
] | [] | false | false | false | false | false | let sub1 f cin =
| let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out | false |
Hacl.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.mul1_add | val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2) | val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2) | let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 74,
"start_col": 0,
"start_line": 71
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
f1: Hacl.Spec.Curve25519.Field64.Core.felem ->
u2: Lib.IntTypes.uint64 ->
f3: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure (Lib.IntTypes.uint64 * Hacl.Spec.Curve25519.Field64.Core.felem) | Prims.Pure | [] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Hacl.Spec.Bignum.Definitions.limb",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"FStar.Pervasives.Native.Mktuple2",
"Prims.unit",
"Hacl.Spec.Bignum.bn_mul1_lshift_add_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_mul1_lshift_add"
] | [] | false | false | false | false | false | let mul1_add f1 u2 f3 =
| let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out | false |
Hacl.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.sub4 | val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2) | val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2) | let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 8,
"end_line": 200,
"start_col": 0,
"start_line": 197
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | f1: Hacl.Spec.Curve25519.Field64.Core.felem -> f2: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure (Lib.IntTypes.uint64 * Hacl.Spec.Curve25519.Field64.Core.felem) | Prims.Pure | [] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Hacl.Spec.Bignum.Base.carry",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"FStar.Pervasives.Native.Mktuple2",
"Lib.IntTypes.uint64",
"Prims.unit",
"Hacl.Spec.Bignum.bn_sub_lemma",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.bn_sub"
] | [] | false | false | false | false | false | let sub4 f1 f2 =
| let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out | false |
Hacl.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.fadd4 | val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime)) | val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime)) | let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 188,
"start_col": 0,
"start_line": 181
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime)) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | f1: Hacl.Spec.Curve25519.Field64.Core.felem -> f2: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem | Prims.Pure | [] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Prims.unit",
"FStar.Math.Lemmas.lemma_mod_plus_distr_r",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Spec.Curve25519.prime",
"FStar.Math.Lemmas.lemma_mod_plus_distr_l",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Prims.op_Addition",
"Hacl.Spec.Curve25519.Field64.Core.carry_pass_lemma",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.carry_pass",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Lib.IntTypes.SEC",
"Hacl.Spec.Curve25519.Field64.Core.add4"
] | [] | false | false | false | false | false | let fadd4 f1 f2 =
| let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out | false |
Hacl.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.lemma_add1_carry | val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38) | val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38) | let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64) | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 103,
"start_col": 0,
"start_line": 90
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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.Curve25519.Field64.Core.felem ->
cin: Lib.IntTypes.uint64{Lib.IntTypes.v cin * 38 < Prims.pow2 63}
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Curve25519.Field64.Core.add1 f (cin *! Lib.IntTypes.u64 38) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c r = _ in
let b1 = r.[ 0 ] +. c *. Lib.IntTypes.u64 38 in
Lib.IntTypes.v b1 == Lib.IntTypes.v r.[ 0 ] + Lib.IntTypes.v c * 38)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.op_Modulus",
"Prims.op_Addition",
"Prims.unit",
"FStar.Math.Lemmas.pow2_plus",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"Lib.Sequence.slice",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.Definitions.bn_eval1",
"Hacl.Spec.Bignum.Definitions.bn_eval_split_i",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.u64",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.add1",
"Lib.IntTypes.op_Star_Bang"
] | [] | false | false | true | false | false | let lemma_add1_carry f cin =
| let c, r = add1 f (cin *! u64 38) in
let b1 = r.[ 0 ] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[ 0 ] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 ==
v f.[ 0 ] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[ 0 ] == (v f.[ 0 ] + v cin * 38) % pow2 64) | false |
Hacl.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.mul4 | val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r) | val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r) | let mul4 f r =
let out = SB.bn_mul f r in
SB.bn_mul_lemma f r;
out | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 261,
"start_col": 0,
"start_line": 258
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38)
let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64)
val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fsub4 f1 f2 =
let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[0] -. c1 *. u64 38 in
let out = r1.[0] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[0] + v b1) % P.prime;
(==) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[0] + (v r1.[0] - v c1 * 38)) % P.prime;
(==) { }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
(==) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out
val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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.Curve25519.Field64.Core.felem -> r: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem_wide | Prims.Pure | [] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Prims.unit",
"Hacl.Spec.Bignum.bn_mul_lemma",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.op_Addition",
"Hacl.Spec.Bignum.bn_mul",
"Hacl.Spec.Curve25519.Field64.Core.felem_wide"
] | [] | false | false | false | false | false | let mul4 f r =
| let out = SB.bn_mul f r in
SB.bn_mul_lemma f r;
out | false |
Hacl.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.fmul4 | val fmul4: f1:felem -> r:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f1 % P.prime) (SD.bn_v r % P.prime)) | val fmul4: f1:felem -> r:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f1 % P.prime) (SD.bn_v r % P.prime)) | let fmul4 f1 r =
let tmp = mul4 f1 r in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (SD.bn_v r) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v r) P.prime;
out | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 275,
"start_col": 0,
"start_line": 270
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38)
let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64)
val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fsub4 f1 f2 =
let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[0] -. c1 *. u64 38 in
let out = r1.[0] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[0] + v b1) % P.prime;
(==) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[0] + (v r1.[0] - v c1 * 38)) % P.prime;
(==) { }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
(==) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out
val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r)
let mul4 f r =
let out = SB.bn_mul f r in
SB.bn_mul_lemma f r;
out
val fmul4: f1:felem -> r:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f1 % P.prime) (SD.bn_v r % P.prime)) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | f1: Hacl.Spec.Curve25519.Field64.Core.felem -> r: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem | Prims.Pure | [] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Prims.unit",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Spec.Curve25519.prime",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.carry_wide",
"Hacl.Spec.Curve25519.Field64.Core.mul4"
] | [] | false | false | false | false | false | let fmul4 f1 r =
| let tmp = mul4 f1 r in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (SD.bn_v r) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v r) P.prime;
out | false |
Hacl.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.sqr4 | val sqr4: f:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v f) | val sqr4: f:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v f) | let sqr4 f =
let out = SB.bn_sqr f in
SB.bn_sqr_lemma f;
out | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 314,
"start_col": 0,
"start_line": 311
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38)
let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64)
val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fsub4 f1 f2 =
let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[0] -. c1 *. u64 38 in
let out = r1.[0] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[0] + v b1) % P.prime;
(==) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[0] + (v r1.[0] - v c1 * 38)) % P.prime;
(==) { }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
(==) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out
val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r)
let mul4 f r =
let out = SB.bn_mul f r in
SB.bn_mul_lemma f r;
out
val fmul4: f1:felem -> r:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f1 % P.prime) (SD.bn_v r % P.prime))
let fmul4 f1 r =
let tmp = mul4 f1 r in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (SD.bn_v r) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v r) P.prime;
out
//121665 < pow2 17
val fmul14: f1:felem -> f2:uint64 ->
Pure felem
(requires v f2 < pow2 17)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f1 % P.prime * v f2 % P.prime)
let fmul14 f1 f2 =
let c0, r0 = mul1 f1 f2 in
assert (SD.bn_v r0 + v c0 * pow2 256 == SD.bn_v f1 * v f2);
SD.bn_eval_bound f1 4;
SD.bn_eval_bound r0 4;
Lemmas.fmul14_bound (SD.bn_v r0) (v c0) (SD.bn_v f1) (v f2);
let out = carry_pass r0 c0 in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c0 }
(SD.bn_v r0 + v c0 * pow2 256) % P.prime;
(==) { }
(SD.bn_v f1 * v f2) % P.prime;
(==) {Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (v f2) P.prime }
(SD.bn_v f1 % P.prime * v f2) % P.prime;
};
out
val sqr4: f:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v f) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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.Curve25519.Field64.Core.felem
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem_wide | Prims.Pure | [] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Prims.unit",
"Hacl.Spec.Bignum.bn_sqr_lemma",
"Lib.IntTypes.U64",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Prims.op_Addition",
"Hacl.Spec.Bignum.bn_sqr",
"Hacl.Spec.Curve25519.Field64.Core.felem_wide"
] | [] | false | false | false | false | false | let sqr4 f =
| let out = SB.bn_sqr f in
SB.bn_sqr_lemma f;
out | false |
Hacl.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.fsqr4 | val fsqr4: f:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f % P.prime) (SD.bn_v f % P.prime)) | val fsqr4: f:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f % P.prime) (SD.bn_v f % P.prime)) | let fsqr4 f =
let tmp = sqr4 f in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f) (SD.bn_v f) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f % P.prime) (SD.bn_v f) P.prime;
out | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 328,
"start_col": 0,
"start_line": 323
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38)
let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64)
val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fsub4 f1 f2 =
let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[0] -. c1 *. u64 38 in
let out = r1.[0] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[0] + v b1) % P.prime;
(==) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[0] + (v r1.[0] - v c1 * 38)) % P.prime;
(==) { }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
(==) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out
val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r)
let mul4 f r =
let out = SB.bn_mul f r in
SB.bn_mul_lemma f r;
out
val fmul4: f1:felem -> r:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f1 % P.prime) (SD.bn_v r % P.prime))
let fmul4 f1 r =
let tmp = mul4 f1 r in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (SD.bn_v r) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v r) P.prime;
out
//121665 < pow2 17
val fmul14: f1:felem -> f2:uint64 ->
Pure felem
(requires v f2 < pow2 17)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f1 % P.prime * v f2 % P.prime)
let fmul14 f1 f2 =
let c0, r0 = mul1 f1 f2 in
assert (SD.bn_v r0 + v c0 * pow2 256 == SD.bn_v f1 * v f2);
SD.bn_eval_bound f1 4;
SD.bn_eval_bound r0 4;
Lemmas.fmul14_bound (SD.bn_v r0) (v c0) (SD.bn_v f1) (v f2);
let out = carry_pass r0 c0 in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c0 }
(SD.bn_v r0 + v c0 * pow2 256) % P.prime;
(==) { }
(SD.bn_v f1 * v f2) % P.prime;
(==) {Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (v f2) P.prime }
(SD.bn_v f1 % P.prime * v f2) % P.prime;
};
out
val sqr4: f:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v f)
let sqr4 f =
let out = SB.bn_sqr f in
SB.bn_sqr_lemma f;
out
val fsqr4: f:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f % P.prime) (SD.bn_v f % P.prime)) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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.Curve25519.Field64.Core.felem -> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem | Prims.Pure | [] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Prims.unit",
"FStar.Math.Lemmas.lemma_mod_mul_distr_r",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Spec.Curve25519.prime",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.carry_wide",
"Hacl.Spec.Curve25519.Field64.Core.sqr4"
] | [] | false | false | false | false | false | let fsqr4 f =
| let tmp = sqr4 f in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f) (SD.bn_v f) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f % P.prime) (SD.bn_v f) P.prime;
out | false |
Hacl.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.lemma_sub1_carry | val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38) | val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38) | let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64) | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 54,
"end_line": 222,
"start_col": 0,
"start_line": 208
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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.Curve25519.Field64.Core.felem ->
cin: Lib.IntTypes.uint64{Lib.IntTypes.v cin * 38 < Prims.pow2 63}
-> FStar.Pervasives.Lemma
(ensures
(let _ = Hacl.Spec.Curve25519.Field64.Core.sub1 f (cin *! Lib.IntTypes.u64 38) in
(let FStar.Pervasives.Native.Mktuple2 #_ #_ c r = _ in
let b1 = r.[ 0 ] -. c *. Lib.IntTypes.u64 38 in
Lib.IntTypes.v b1 == Lib.IntTypes.v r.[ 0 ] - Lib.IntTypes.v c * 38)
<:
Type0)) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Prims._assert",
"Prims.eq2",
"Prims.int",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"Prims.op_Modulus",
"Prims.op_Subtraction",
"Prims.unit",
"FStar.Math.Lemmas.pow2_plus",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"Lib.Sequence.slice",
"Prims.op_Addition",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Hacl.Spec.Bignum.Definitions.bn_eval1",
"Hacl.Spec.Bignum.Definitions.bn_eval_split_i",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.u64",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.sub1",
"Lib.IntTypes.op_Star_Bang"
] | [] | false | false | true | false | false | let lemma_sub1_carry f cin =
| let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[ 0 ] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[ 0 ] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 ==
v f.[ 0 ] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[ 0 ] == (v f.[ 0 ] - v cin * 38) % pow2 64) | false |
Hacl.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.fmul14 | val fmul14: f1:felem -> f2:uint64 ->
Pure felem
(requires v f2 < pow2 17)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f1 % P.prime * v f2 % P.prime) | val fmul14: f1:felem -> f2:uint64 ->
Pure felem
(requires v f2 < pow2 17)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f1 % P.prime * v f2 % P.prime) | let fmul14 f1 f2 =
let c0, r0 = mul1 f1 f2 in
assert (SD.bn_v r0 + v c0 * pow2 256 == SD.bn_v f1 * v f2);
SD.bn_eval_bound f1 4;
SD.bn_eval_bound r0 4;
Lemmas.fmul14_bound (SD.bn_v r0) (v c0) (SD.bn_v f1) (v f2);
let out = carry_pass r0 c0 in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c0 }
(SD.bn_v r0 + v c0 * pow2 256) % P.prime;
(==) { }
(SD.bn_v f1 * v f2) % P.prime;
(==) {Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (v f2) P.prime }
(SD.bn_v f1 % P.prime * v f2) % P.prime;
};
out | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 302,
"start_col": 0,
"start_line": 285
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38)
let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64)
val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fsub4 f1 f2 =
let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[0] -. c1 *. u64 38 in
let out = r1.[0] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[0] + v b1) % P.prime;
(==) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[0] + (v r1.[0] - v c1 * 38)) % P.prime;
(==) { }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
(==) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out
val mul4: f:felem -> r:felem ->
Pure felem_wide
(requires True)
(ensures fun out ->
SD.bn_v out == SD.bn_v f * SD.bn_v r)
let mul4 f r =
let out = SB.bn_mul f r in
SB.bn_mul_lemma f r;
out
val fmul4: f1:felem -> r:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fmul (SD.bn_v f1 % P.prime) (SD.bn_v r % P.prime))
let fmul4 f1 r =
let tmp = mul4 f1 r in
let out = carry_wide tmp in
Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (SD.bn_v r) P.prime;
Math.Lemmas.lemma_mod_mul_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v r) P.prime;
out
//121665 < pow2 17
val fmul14: f1:felem -> f2:uint64 ->
Pure felem
(requires v f2 < pow2 17)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f1 % P.prime * v f2 % P.prime) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | f1: Hacl.Spec.Curve25519.Field64.Core.felem -> f2: Lib.IntTypes.uint64
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem | Prims.Pure | [] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Spec.Curve25519.prime",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Prims.op_Addition",
"Prims.pow2",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.Curve25519.Field64.Core.carry_pass_lemma",
"Prims.squash",
"FStar.Math.Lemmas.lemma_mod_mul_distr_l",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.carry_pass",
"Hacl.Spec.Curve25519.Field64.Lemmas.fmul14_bound",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"Prims._assert",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Hacl.Spec.Curve25519.Field64.Core.mul1"
] | [] | false | false | false | false | false | let fmul14 f1 f2 =
| let c0, r0 = mul1 f1 f2 in
assert (SD.bn_v r0 + v c0 * pow2 256 == SD.bn_v f1 * v f2);
SD.bn_eval_bound f1 4;
SD.bn_eval_bound r0 4;
Lemmas.fmul14_bound (SD.bn_v r0) (v c0) (SD.bn_v f1) (v f2);
let out = carry_pass r0 c0 in
calc ( == ) {
SD.bn_v out % P.prime;
( == ) { carry_pass_lemma r0 c0 }
(SD.bn_v r0 + v c0 * pow2 256) % P.prime;
( == ) { () }
(SD.bn_v f1 * v f2) % P.prime;
( == ) { Math.Lemmas.lemma_mod_mul_distr_l (SD.bn_v f1) (v f2) P.prime }
((SD.bn_v f1 % P.prime) * v f2) % P.prime;
};
out | false |
Steel.ST.Printf.fst | Steel.ST.Printf.fragments | val fragments : Type0 | let fragments = list fragment | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 29,
"end_line": 175,
"start_col": 0,
"start_line": 175
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Steel.ST.Printf.fragment"
] | [] | false | false | false | true | true | let fragments =
| list fragment | false |
|
Steel.ST.Printf.fst | Steel.ST.Printf.__printf_reduce__ | val __printf_reduce__ : Prims.eqtype | let __printf_reduce__ = unit | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 28,
"end_line": 124,
"start_col": 0,
"start_line": 124
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Prims.eqtype | Prims.Tot | [
"total"
] | [] | [
"Prims.unit"
] | [] | false | false | false | true | false | let __printf_reduce__ =
| unit | false |
|
Steel.ST.Printf.fst | Steel.ST.Printf.parse_format_string | val parse_format_string (s: string) : option fragments | val parse_format_string (s: string) : option fragments | let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s) | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 35,
"end_line": 247,
"start_col": 0,
"start_line": 244
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__] | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.string -> FStar.Pervasives.Native.option Steel.ST.Printf.fragments | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Steel.ST.Printf.parse_format",
"FStar.String.list_of_string",
"FStar.Pervasives.Native.option",
"Steel.ST.Printf.fragments"
] | [] | false | false | false | true | false | let parse_format_string (s: string) : option fragments =
| parse_format (list_of_string s) | false |
Steel.ST.Printf.fst | Steel.ST.Printf.frag_t | val frag_t : Type | let frag_t = either string (a:arg & arg_t a) | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 44,
"end_line": 274,
"start_col": 0,
"start_line": 274
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.either",
"Prims.string",
"Prims.dtuple2",
"Steel.ST.Printf.arg",
"Steel.ST.Printf.arg_t"
] | [] | false | false | false | true | true | let frag_t =
| either string (a: arg & arg_t a) | false |
|
Steel.ST.Printf.fst | Steel.ST.Printf.live_frag | val live_frag (f: frag_t) : vprop | val live_frag (f: frag_t) : vprop | let live_frag (f: frag_t) : vprop =
live_frag0 f | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 14,
"end_line": 291,
"start_col": 0,
"start_line": 290
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__] | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Steel.ST.Printf.frag_t -> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.Printf.frag_t",
"Steel.ST.Printf.live_frag0",
"Steel.Effect.Common.vprop"
] | [] | false | false | false | true | false | let live_frag (f: frag_t) : vprop =
| live_frag0 f | false |
Steel.ST.Printf.fst | Steel.ST.Printf.normal | val normal (#a: Type) (x: a) : a | val normal (#a: Type) (x: a) : a | let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 6,
"end_line": 351,
"start_col": 0,
"start_line": 343
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: a -> a | Prims.Tot | [
"total"
] | [] | [
"FStar.Pervasives.norm",
"Prims.Cons",
"FStar.Pervasives.norm_step",
"FStar.Pervasives.iota",
"FStar.Pervasives.zeta",
"FStar.Pervasives.delta_attr",
"Prims.string",
"Prims.Nil",
"FStar.Pervasives.delta_only",
"FStar.Pervasives.primops",
"FStar.Pervasives.simplify"
] | [] | false | false | false | true | false | let normal (#a: Type) (x: a) : a =
| FStar.Pervasives.norm [
iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify
]
x | false |
Steel.ST.Printf.fst | Steel.ST.Printf.lmbuffer | val lmbuffer : a: Type0 -> l: FStar.UInt32.t -> Type0 | let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
} | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 72,
"start_col": 0,
"start_line": 69
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l` | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Type0 -> l: FStar.UInt32.t -> Type0 | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"Steel.ST.Array.array",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"Steel.ST.Array.length",
"FStar.UInt32.v"
] | [] | false | false | false | true | true | let lmbuffer a l =
| b: A.array a {A.length b == U32.v l} | false |
|
Steel.ST.Printf.fst | Steel.ST.Printf.base_typ_as_type | val base_typ_as_type (b: base_typ) : Type0 | val base_typ_as_type (b: base_typ) : Type0 | let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 27,
"end_line": 164,
"start_col": 0,
"start_line": 152
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__] | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: Steel.ST.Printf.base_typ -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.Printf.base_typ",
"Prims.bool",
"FStar.String.char",
"Prims.string",
"FStar.UInt8.t",
"FStar.UInt16.t",
"FStar.UInt32.t",
"FStar.UInt64.t",
"FStar.Int8.t",
"FStar.Int16.t",
"FStar.Int32.t",
"FStar.Int64.t"
] | [] | false | false | false | true | true | let base_typ_as_type (b: base_typ) : Type0 =
| match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t | false |
Steel.ST.Printf.fst | Steel.ST.Printf.fragment_printer | val fragment_printer : Type | let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc) | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 56,
"end_line": 361,
"start_col": 0,
"start_line": 359
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Steel.ST.Printf.frag_t",
"Prims.unit",
"Steel.ST.Printf.live_frags",
"Steel.Effect.Common.vprop"
] | [] | false | false | false | true | true | let fragment_printer =
| acc: list frag_t -> STT unit (live_frags acc) (fun _ -> live_frags acc) | false |
|
FStar.UInt8.fst | FStar.UInt8.v | val v (x:t) : Tot (uint_t n) | val v (x:t) : Tot (uint_t n) | let v x = x.v | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 13,
"end_line": 28,
"start_col": 0,
"start_line": 28
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt8.t -> FStar.UInt.uint_t FStar.UInt8.n | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.__proj__Mk__item__v",
"FStar.UInt.uint_t",
"FStar.UInt8.n"
] | [] | false | false | false | true | false | let v x =
| x.v | false |
Steel.ST.Printf.fst | Steel.ST.Printf.elim_unit_arrow | val elim_unit_arrow (#t: _) (f: (unit -> t)) : t | val elim_unit_arrow (#t: _) (f: (unit -> t)) : t | let elim_unit_arrow #t (f:unit -> t) : t = f () | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 47,
"end_line": 442,
"start_col": 0,
"start_line": 442
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: (_: Prims.unit -> t) -> t | Prims.Tot | [
"total"
] | [] | [
"Prims.unit"
] | [] | false | false | false | true | false | let elim_unit_arrow #t (f: (unit -> t)) : t =
| f () | false |
Steel.ST.Printf.fst | Steel.ST.Printf.no_inst | val no_inst: #a: _ -> #b: (a -> Type) -> f: (#x: a -> b x) -> unit -> #x: a -> b x | val no_inst: #a: _ -> #b: (a -> Type) -> f: (#x: a -> b x) -> unit -> #x: a -> b x | let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 84,
"end_line": 440,
"start_col": 0,
"start_line": 440
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc) | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: b x -> _: Prims.unit -> b x | Prims.Tot | [
"total"
] | [] | [
"Prims.unit"
] | [] | false | false | false | false | false | let no_inst #a (#b: (a -> Type)) (f: (#x: a -> b x)) : unit -> #x: a -> b x =
| fun () -> f | false |
Steel.ST.Printf.fst | Steel.ST.Printf.format_string | val format_string : Type0 | let format_string = s:string{normal #bool (Some? (parse_format_string s))} | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 74,
"end_line": 492,
"start_col": 0,
"start_line": 492
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__] | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | Type0 | Prims.Tot | [
"total"
] | [] | [
"Prims.string",
"Prims.b2t",
"Steel.ST.Printf.normal",
"Prims.bool",
"FStar.Pervasives.Native.uu___is_Some",
"Steel.ST.Printf.fragments",
"Steel.ST.Printf.parse_format_string"
] | [] | false | false | false | true | true | let format_string =
| s: string{normal #bool (Some? (parse_format_string s))} | false |
|
Steel.ST.Printf.fst | Steel.ST.Printf.live_frag0 | val live_frag0 (f: frag_t) : vprop | val live_frag0 (f: frag_t) : vprop | let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v) | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 64,
"end_line": 286,
"start_col": 0,
"start_line": 279
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__] | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | f: Steel.ST.Printf.frag_t -> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.Printf.frag_t",
"Prims.string",
"Steel.Effect.Common.emp",
"Prims.dtuple2",
"Steel.ST.Printf.arg",
"Steel.ST.Printf.arg_t",
"Steel.ST.Printf.base_typ",
"Steel.ST.Printf.Base",
"Steel.ST.Printf.Any",
"FStar.UInt32.t",
"Steel.ST.Printf.lmbuffer",
"Steel.ST.Printf.base_typ_as_type",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.Array.pts_to",
"FStar.Ghost.reveal",
"Steel.Effect.Common.vprop"
] | [] | false | false | false | true | false | let live_frag0 (f: frag_t) : vprop =
| match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _ , _ |) -> emp
| (| Any , _ |) -> emp
| (| Array _ , Lift ((| _ , b |), p, v) |) -> A.pts_to b p v) | false |
Steel.ST.Printf.fst | Steel.ST.Printf.live_frags | val live_frags (l: list frag_t) : vprop | val live_frags (l: list frag_t) : vprop | let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 45,
"end_line": 298,
"start_col": 0,
"start_line": 295
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__] | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Prims.list Steel.ST.Printf.frag_t -> Steel.Effect.Common.vprop | Prims.Tot | [
"total"
] | [] | [
"Prims.list",
"Steel.ST.Printf.frag_t",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.star",
"Steel.ST.Printf.live_frag",
"Steel.ST.Printf.live_frags",
"Steel.Effect.Common.vprop"
] | [
"recursion"
] | false | false | false | true | false | let rec live_frags (l: list frag_t) : vprop =
| match l with
| [] -> emp
| a :: q -> (live_frag a) `star` (live_frags q) | false |
Steel.ST.Printf.fst | Steel.ST.Printf.printf | val printf : s:normal format_string -> normal (interpret_format_string s) | val printf : s:normal format_string -> normal (interpret_format_string s) | let printf = intro_normal_f #format_string interpret_format_string printf' | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 74,
"end_line": 529,
"start_col": 0,
"start_line": 529
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Steel.ST.Printf.normal Steel.ST.Printf.format_string
-> Steel.ST.Printf.normal (Steel.ST.Printf.interpret_format_string s) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.Printf.intro_normal_f",
"Steel.ST.Printf.format_string",
"Steel.ST.Printf.interpret_format_string",
"Steel.ST.Printf.printf'"
] | [] | false | false | false | false | false | let printf =
| intro_normal_f #format_string interpret_format_string printf' | false |
Steel.ST.Printf.fst | Steel.ST.Printf.arg_t | val arg_t (a: arg) : Type u#1 | val arg_t (a: arg) : Type u#1 | let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a) | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 48,
"end_line": 270,
"start_col": 0,
"start_line": 266
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__] | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: Steel.ST.Printf.arg -> Type | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.Printf.arg",
"Steel.ST.Printf.base_typ",
"Steel.ST.Printf.lift",
"Steel.ST.Printf.base_typ_as_type",
"FStar.Pervasives.Native.tuple3",
"Prims.dtuple2",
"FStar.UInt32.t",
"Steel.ST.Printf.lmbuffer",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"FStar.Pervasives.dtuple3",
"Prims.unit"
] | [
"recursion"
] | false | false | false | true | true | let rec arg_t (a: arg) : Type u#1 =
| match a with
| Base t -> lift (base_typ_as_type t)
| Array t ->
lift ((l: UInt32.t & lmbuffer (base_typ_as_type t) l) &
perm &
Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a: Type0 & (a -> StTrivial unit) & a) | false |
FStar.UInt8.fst | FStar.UInt8.zero | val zero : x:t{v x = 0} | val zero : x:t{v x = 0} | let zero = uint_to_t 0 | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 39,
"start_col": 0,
"start_line": 39
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt8.t{FStar.UInt8.v x = 0} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.uint_to_t"
] | [] | false | false | false | false | false | let zero =
| uint_to_t 0 | false |
Steel.ST.Printf.fst | Steel.ST.Printf.skip | val skip : s:normal format_string -> normal (interpret_format_string s) | val skip : s:normal format_string -> normal (interpret_format_string s) | let skip = intro_normal_f #format_string interpret_format_string skip' | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 70,
"end_line": 543,
"start_col": 0,
"start_line": 543
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance.
noextract inline_for_extraction
let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> noop ()))
noextract inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Steel.ST.Printf.normal Steel.ST.Printf.format_string
-> Steel.ST.Printf.normal (Steel.ST.Printf.interpret_format_string s) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.Printf.intro_normal_f",
"Steel.ST.Printf.format_string",
"Steel.ST.Printf.interpret_format_string",
"Steel.ST.Printf.skip'"
] | [] | false | false | false | false | false | let skip =
| intro_normal_f #format_string interpret_format_string skip' | false |
FStar.UInt8.fst | FStar.UInt8.one | val one : x:t{v x = 1} | val one : x:t{v x = 1} | let one = uint_to_t 1 | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 21,
"end_line": 41,
"start_col": 0,
"start_line": 41
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt8.t{FStar.UInt8.v x = 1} | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt8.uint_to_t"
] | [] | false | false | false | false | false | let one =
| uint_to_t 1 | false |
FStar.UInt8.fst | FStar.UInt8.uint_to_t | val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x)) | val uint_to_t (x:uint_t n) : Pure t
(requires True)
(ensures (fun y -> v y = x)) | let uint_to_t x = Mk x | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 22,
"end_line": 31,
"start_col": 0,
"start_line": 31
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt.uint_t FStar.UInt8.n -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt.uint_t",
"FStar.UInt8.n",
"FStar.UInt8.Mk",
"FStar.UInt8.t"
] | [] | false | false | false | false | false | let uint_to_t x =
| Mk x | false |
FStar.UInt8.fst | FStar.UInt8.add_underspec | val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c)) | val add_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a + v b) n ==> v a + v b = v c)) | let add_underspec a b = Mk (add_underspec (v a) (v b)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 54,
"end_line": 45,
"start_col": 0,
"start_line": 45
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.add_underspec",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | false | false | false | false | false | let add_underspec a b =
| Mk (add_underspec (v a) (v b)) | false |
FStar.UInt8.fst | FStar.UInt8.add | val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c)) | val add (a:t) (b:t) : Pure t
(requires (size (v a + v b) n))
(ensures (fun c -> v a + v b = v c)) | let add a b = Mk (add (v a) (v b)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 43,
"start_col": 0,
"start_line": 43
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.add",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | false | false | false | false | false | let add a b =
| Mk (add (v a) (v b)) | false |
Hacl.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.fsub4 | val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime)) | val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime)) | let fsub4 f1 f2 =
let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[0] -. c1 *. u64 38 in
let out = r1.[0] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[0] + v b1) % P.prime;
(==) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[0] + (v r1.[0] - v c1 * 38)) % P.prime;
(==) { }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
(==) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 249,
"start_col": 0,
"start_line": 231
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime)
let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out
val add4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f1 + SD.bn_v f2)
let add4 f1 f2 =
let c, out = SB.bn_add f1 f2 in
SB.bn_add_lemma f1 f2;
c, out
val fadd4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fadd (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime))
let fadd4 f1 f2 =
let c0, out0 = add4 f1 f2 in
let out = carry_pass out0 c0 in
carry_pass_lemma out0 c0;
assert (SD.bn_v out % P.prime == (SD.bn_v f1 + SD.bn_v f2) % P.prime);
Math.Lemmas.lemma_mod_plus_distr_l (SD.bn_v f1) (SD.bn_v f2) P.prime;
Math.Lemmas.lemma_mod_plus_distr_r (SD.bn_v f1 % P.prime) (SD.bn_v f2) P.prime;
out
val sub4: f1:felem -> f2:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f1 - SD.bn_v f2)
let sub4 f1 f2 =
let c, out = SB.bn_sub f1 f2 in
SB.bn_sub_lemma f1 f2;
c, out
val lemma_sub1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
v b1 == v r.[0] - v c * 38)
let lemma_sub1_carry f cin =
let c, r = sub1 f (cin *! u64 38) in
let b1 = r.[0] -. c *. u64 38 in
assert (SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) - v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) - v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] - v cin * 38) % pow2 64)
val fsub4: f1:felem -> f2:felem ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == P.fsub (SD.bn_v f1 % P.prime) (SD.bn_v f2 % P.prime)) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 | f1: Hacl.Spec.Curve25519.Field64.Core.felem -> f2: Hacl.Spec.Curve25519.Field64.Core.felem
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem | Prims.Pure | [] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Spec.Curve25519.prime",
"Prims.op_Subtraction",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"Prims.pow2",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Pervasives.assert_norm",
"Prims.b2t",
"Prims.op_Equality",
"Prims.squash",
"Hacl.Spec.Curve25519.Field64.Core.lemma_sub1_carry",
"Hacl.Spec.Curve25519.Field64.Lemmas.lemma_fsub4",
"Hacl.Spec.Bignum.Definitions.bn_upd_eval",
"Lib.Sequence.lseq",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.upd",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Prims.l_imp",
"Prims.op_LessThan",
"Prims.op_disEquality",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Subtraction_Dot",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.u64",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.sub1",
"Lib.IntTypes.op_Star_Bang",
"Hacl.Spec.Curve25519.Field64.Core.sub4"
] | [] | false | false | false | false | false | let fsub4 f1 f2 =
| let c0, r0 = sub4 f1 f2 in
let c1, r1 = sub1 r0 (c0 *! u64 38) in
let b1 = r1.[ 0 ] -. c1 *. u64 38 in
let out = r1.[ 0 ] <- b1 in
SD.bn_upd_eval r1 b1 0;
calc ( == ) {
SD.bn_v out % P.prime;
( == ) { assert_norm (pow2 0 = 1) }
(SD.bn_v r1 - v r1.[ 0 ] + v b1) % P.prime;
( == ) { lemma_sub1_carry r0 c0 }
(SD.bn_v r1 - v r1.[ 0 ] + (v r1.[ 0 ] - v c1 * 38)) % P.prime;
( == ) { () }
(SD.bn_v f1 - SD.bn_v f2 + v c0 * pow2 256 - v c0 * 38 + v c1 * pow2 256 - v c1 * 38) % P.prime;
( == ) { Lemmas.lemma_fsub4 (SD.bn_v f1) (SD.bn_v f2) (v c0) (v c1) }
(SD.bn_v f1 % P.prime - SD.bn_v f2 % P.prime) % P.prime;
};
out | false |
FStar.UInt8.fst | FStar.UInt8.add_mod | val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) | val add_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.add_mod (v a) (v b) = v c)) | let add_mod a b = Mk (add_mod (v a) (v b)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 47,
"start_col": 0,
"start_line": 47
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.add_mod",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | false | false | false | false | false | let add_mod a b =
| Mk (add_mod (v a) (v b)) | false |
Steel.ST.Printf.fst | Steel.ST.Printf.coerce | val coerce (x: 'a{'a == 'b}) : 'b | val coerce (x: 'a{'a == 'b}) : 'b | let coerce (x:'a{'a == 'b}) : 'b = x | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 36,
"end_line": 355,
"start_col": 0,
"start_line": 355
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: 'a{'a == 'b} -> 'b | Prims.Tot | [
"total"
] | [] | [
"Prims.eq2"
] | [] | false | false | false | false | false | let coerce (x: 'a{'a == 'b}) : 'b =
| x | false |
FStar.UInt8.fst | FStar.UInt8.sub | val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c)) | val sub (a:t) (b:t) : Pure t
(requires (size (v a - v b) n))
(ensures (fun c -> v a - v b = v c)) | let sub a b = Mk (sub (v a) (v b)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 49,
"start_col": 0,
"start_line": 49
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.sub",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | false | false | false | false | false | let sub a b =
| Mk (sub (v a) (v b)) | false |
Steel.ST.Printf.fst | Steel.ST.Printf.parse_format | val parse_format (s: list char) : Tot (option fragments) (decreases (L.length s)) | val parse_format (s: list char) : Tot (option fragments) (decreases (L.length s)) | let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s') | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 34,
"end_line": 238,
"start_col": 0,
"start_line": 182
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__] | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Prims.list FStar.String.char
-> Prims.Tot (FStar.Pervasives.Native.option Steel.ST.Printf.fragments) | Prims.Tot | [
"total",
""
] | [] | [
"Prims.list",
"FStar.String.char",
"FStar.Pervasives.Native.Some",
"Steel.ST.Printf.fragments",
"Prims.Nil",
"Steel.ST.Printf.fragment",
"FStar.Pervasives.Native.None",
"Steel.ST.Printf.Any",
"Steel.ST.Printf.parse_format",
"Prims.Cons",
"Steel.ST.Printf.Base",
"Steel.ST.Printf.U8",
"Steel.ST.Printf.U16",
"Steel.ST.Printf.U32",
"Steel.ST.Printf.U64",
"FStar.Pervasives.Native.option",
"Steel.ST.Printf.Bool",
"Steel.ST.Printf.Char",
"Steel.ST.Printf.String",
"Steel.ST.Printf.I8",
"Steel.ST.Printf.I16",
"Steel.ST.Printf.I32",
"Steel.ST.Printf.I64",
"FStar.Char.char",
"Prims.string",
"Steel.ST.Printf.Frag",
"FStar.String.string_of_list",
"FStar.String.list_of_string",
"Steel.ST.Printf.base_typ",
"Steel.ST.Printf.Interpolate",
"Steel.ST.Printf.Array",
"Steel.ST.Printf.arg"
] | [
"recursion"
] | false | false | false | true | false | let rec parse_format (s: list char) : Tot (option fragments) (decreases (L.length s)) =
| let add_dir (d: arg) (ods: option fragments) =
match ods with
| None -> None
| Some ds -> Some (Interpolate d :: ds)
in
let head_buffer (ods: option fragments) =
match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c: char) (ods: option fragments) =
match ods with
| Some (Frag s :: rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
| '%' :: 'a' :: s' -> add_dir Any (parse_format s')
| '%' :: 'x' :: s' -> head_buffer (parse_format ('%' :: s'))
| '%' :: 'u' :: s' ->
(match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None)
| '%' :: c :: s' ->
(match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None)
| c :: s' -> cons_frag c (parse_format s') | false |
FStar.UInt8.fst | FStar.UInt8.sub_underspec | val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c)) | val sub_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a - v b) n ==> v a - v b = v c)) | let sub_underspec a b = Mk (sub_underspec (v a) (v b)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 54,
"end_line": 51,
"start_col": 0,
"start_line": 51
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.sub_underspec",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | false | false | false | false | false | let sub_underspec a b =
| Mk (sub_underspec (v a) (v b)) | false |
FStar.UInt8.fst | FStar.UInt8.mul | val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c)) | val mul (a:t) (b:t) : Pure t
(requires (size (v a * v b) n))
(ensures (fun c -> v a * v b = v c)) | let mul a b = Mk (mul (v a) (v b)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 55,
"start_col": 0,
"start_line": 55
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.mul",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | false | false | false | false | false | let mul a b =
| Mk (mul (v a) (v b)) | false |
FStar.UInt8.fst | FStar.UInt8.mul_underspec | val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c)) | val mul_underspec (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c ->
size (v a * v b) n ==> v a * v b = v c)) | let mul_underspec a b = Mk (mul_underspec (v a) (v b)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 54,
"end_line": 57,
"start_col": 0,
"start_line": 57
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.mul_underspec",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | false | false | false | false | false | let mul_underspec a b =
| Mk (mul_underspec (v a) (v b)) | false |
FStar.UInt8.fst | FStar.UInt8.sub_mod | val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) | val sub_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.sub_mod (v a) (v b) = v c)) | let sub_mod a b = Mk (sub_mod (v a) (v b)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 53,
"start_col": 0,
"start_line": 53
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.sub_mod",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | false | false | false | false | false | let sub_mod a b =
| Mk (sub_mod (v a) (v b)) | false |
FStar.UInt8.fst | FStar.UInt8.mul_mod | val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) | val mul_mod (a:t) (b:t) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mul_mod (v a) (v b) = v c)) | let mul_mod a b = Mk (mul_mod (v a) (v b)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 42,
"end_line": 59,
"start_col": 0,
"start_line": 59
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b))
let mul_underspec a b = Mk (mul_underspec (v a) (v b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> b: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.mul_mod",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | false | false | false | false | false | let mul_mod a b =
| Mk (mul_mod (v a) (v b)) | false |
FStar.UInt8.fst | FStar.UInt8.rem | val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) | val rem (a:t) (b:t{v b <> 0}) : Pure t
(requires True)
(ensures (fun c -> FStar.UInt.mod (v a) (v b) = v c)) | let rem a b = Mk (mod (v a) (v b)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 63,
"start_col": 0,
"start_line": 63
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b))
let mul_underspec a b = Mk (mul_underspec (v a) (v b))
let mul_mod a b = Mk (mul_mod (v a) (v b))
let div a b = Mk (div (v a) (v b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> b: FStar.UInt8.t{FStar.UInt8.v b <> 0} -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.int",
"FStar.UInt8.v",
"FStar.UInt8.Mk",
"FStar.UInt.mod",
"FStar.UInt8.n"
] | [] | false | false | false | false | false | let rem a b =
| Mk (mod (v a) (v b)) | false |
FStar.UInt8.fst | FStar.UInt8.logxor | val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z)) | val logxor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logxor` v y == v z)) | let logxor x y = Mk (logxor (v x) (v y)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 67,
"start_col": 0,
"start_line": 67
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b))
let mul_underspec a b = Mk (mul_underspec (v a) (v b))
let mul_mod a b = Mk (mul_mod (v a) (v b))
let div a b = Mk (div (v a) (v b))
let rem a b = Mk (mod (v a) (v b))
let logand x y = Mk (logand (v x) (v y)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.logxor",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | false | false | false | false | false | let logxor x y =
| Mk (logxor (v x) (v y)) | false |
FStar.UInt8.fst | FStar.UInt8.logor | val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z)) | val logor (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logor` v y == v z)) | let logor x y = Mk (logor (v x) (v y)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 38,
"end_line": 69,
"start_col": 0,
"start_line": 69
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b))
let mul_underspec a b = Mk (mul_underspec (v a) (v b))
let mul_mod a b = Mk (mul_mod (v a) (v b))
let div a b = Mk (div (v a) (v b))
let rem a b = Mk (mod (v a) (v b))
let logand x y = Mk (logand (v x) (v y))
let logxor x y = Mk (logxor (v x) (v y)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.logor",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | false | false | false | false | false | let logor x y =
| Mk (logor (v x) (v y)) | false |
FStar.UInt8.fst | FStar.UInt8.div | val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c)) | val div (a:t) (b:t{v b <> 0}) : Pure t
(requires (True))
(ensures (fun c -> v a / v b = v c)) | let div a b = Mk (div (v a) (v b)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 34,
"end_line": 61,
"start_col": 0,
"start_line": 61
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b))
let mul_underspec a b = Mk (mul_underspec (v a) (v b))
let mul_mod a b = Mk (mul_mod (v a) (v b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> b: FStar.UInt8.t{FStar.UInt8.v b <> 0} -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"Prims.b2t",
"Prims.op_disEquality",
"Prims.int",
"FStar.UInt8.v",
"FStar.UInt8.Mk",
"FStar.UInt.div",
"FStar.UInt8.n"
] | [] | false | false | false | false | false | let div a b =
| Mk (div (v a) (v b)) | false |
FStar.UInt8.fst | FStar.UInt8.logand | val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z)) | val logand (x:t) (y:t) : Pure t
(requires True)
(ensures (fun z -> v x `logand` v y = v z)) | let logand x y = Mk (logand (v x) (v y)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 40,
"end_line": 65,
"start_col": 0,
"start_line": 65
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b))
let mul_underspec a b = Mk (mul_underspec (v a) (v b))
let mul_mod a b = Mk (mul_mod (v a) (v b))
let div a b = Mk (div (v a) (v b))
let rem a b = Mk (mod (v a) (v b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt8.t -> y: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.logand",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | false | false | false | false | false | let logand x y =
| Mk (logand (v x) (v y)) | false |
FStar.UInt8.fst | FStar.UInt8.shift_right | val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) | val shift_right (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_right (v a) (UInt32.v s) = v c)) | let shift_right a s = Mk (shift_right (v a) (UInt32.v s)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 57,
"end_line": 73,
"start_col": 0,
"start_line": 73
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b))
let mul_underspec a b = Mk (mul_underspec (v a) (v b))
let mul_mod a b = Mk (mul_mod (v a) (v b))
let div a b = Mk (div (v a) (v b))
let rem a b = Mk (mod (v a) (v b))
let logand x y = Mk (logand (v x) (v y))
let logxor x y = Mk (logxor (v x) (v y))
let logor x y = Mk (logor (v x) (v y))
let lognot x = Mk (lognot (v x)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt32.t",
"FStar.UInt8.Mk",
"FStar.UInt.shift_right",
"FStar.UInt8.n",
"FStar.UInt8.v",
"FStar.UInt32.v"
] | [] | false | false | false | false | false | let shift_right a s =
| Mk (shift_right (v a) (UInt32.v s)) | false |
FStar.UInt8.fst | FStar.UInt8.lognot | val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z)) | val lognot (x:t) : Pure t
(requires True)
(ensures (fun z -> lognot (v x) == v z)) | let lognot x = Mk (lognot (v x)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 32,
"end_line": 71,
"start_col": 0,
"start_line": 71
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b))
let mul_underspec a b = Mk (mul_underspec (v a) (v b))
let mul_mod a b = Mk (mul_mod (v a) (v b))
let div a b = Mk (div (v a) (v b))
let rem a b = Mk (mod (v a) (v b))
let logand x y = Mk (logand (v x) (v y))
let logxor x y = Mk (logxor (v x) (v y))
let logor x y = Mk (logor (v x) (v y)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | x: FStar.UInt8.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt8.Mk",
"FStar.UInt.lognot",
"FStar.UInt8.n",
"FStar.UInt8.v"
] | [] | false | false | false | false | false | let lognot x =
| Mk (lognot (v x)) | false |
FStar.UInt8.fst | FStar.UInt8.shift_left | val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) | val shift_left (a:t) (s:UInt32.t) : Pure t
(requires (UInt32.v s < n))
(ensures (fun c -> FStar.UInt.shift_left (v a) (UInt32.v s) = v c)) | let shift_left a s = Mk (shift_left (v a) (UInt32.v s)) | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 55,
"end_line": 77,
"start_col": 0,
"start_line": 77
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b))
let mul_underspec a b = Mk (mul_underspec (v a) (v b))
let mul_mod a b = Mk (mul_mod (v a) (v b))
let div a b = Mk (div (v a) (v b))
let rem a b = Mk (mod (v a) (v b))
let logand x y = Mk (logand (v x) (v y))
let logxor x y = Mk (logxor (v x) (v y))
let logor x y = Mk (logor (v x) (v y))
let lognot x = Mk (lognot (v x))
let shift_right a s = Mk (shift_right (v a) (UInt32.v s))
#push-options "--z3rlimit 80 --fuel 1" //AR: working around the interleaving semantics of pragmas | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> s: FStar.UInt32.t -> Prims.Pure FStar.UInt8.t | Prims.Pure | [] | [] | [
"FStar.UInt8.t",
"FStar.UInt32.t",
"FStar.UInt8.Mk",
"FStar.UInt.shift_left",
"FStar.UInt8.n",
"FStar.UInt8.v",
"FStar.UInt32.v"
] | [] | false | false | false | false | false | let shift_left a s =
| Mk (shift_left (v a) (UInt32.v s)) | false |
Steel.ST.Printf.fst | Steel.ST.Printf.intro_normal_f | val intro_normal_f (#a: Type) (b: (a -> Type)) (f: (x: a -> b x)) : (x: (normal a) -> normal (b x)) | val intro_normal_f (#a: Type) (b: (a -> Type)) (f: (x: a -> b x)) : (x: (normal a) -> normal (b x)) | let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 5,
"end_line": 517,
"start_col": 0,
"start_line": 515
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | b: (_: a -> Type) -> f: (x: a -> b x) -> x: Steel.ST.Printf.normal a -> Steel.ST.Printf.normal (b x) | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.Printf.normal"
] | [] | false | false | false | false | false | let intro_normal_f (#a: Type) (b: (a -> Type)) (f: (x: a -> b x)) : (x: (normal a) -> normal (b x)) =
| f | false |
FStar.UInt8.fst | FStar.UInt8.lemma_sub_msbs | val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) | val lemma_sub_msbs (a:t) (b:t)
: Lemma ((msb (v a) = msb (v b)) ==> (v a < v b <==> msb (v (sub_mod a b)))) | let lemma_sub_msbs a b
= from_vec_propriety (to_vec (v a)) 1;
from_vec_propriety (to_vec (v b)) 1;
from_vec_propriety (to_vec (v (sub_mod a b))) 1 | {
"file_name": "ulib/FStar.UInt8.fst",
"git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | {
"end_col": 53,
"end_line": 82,
"start_col": 0,
"start_line": 79
} | (*
Copyright 2008-2019 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.UInt8
(**** THIS MODULE IS GENERATED AUTOMATICALLY USING [mk_int.sh], DO NOT EDIT DIRECTLY ****)
open FStar.UInt
open FStar.Mul
#set-options "--max_fuel 0 --max_ifuel 0"
type t : eqtype =
| Mk: v:uint_t n -> t
let v x = x.v
irreducible
let uint_to_t x = Mk x
let uv_inv _ = ()
let vu_inv _ = ()
let v_inj _ _ = ()
let zero = uint_to_t 0
let one = uint_to_t 1
let add a b = Mk (add (v a) (v b))
let add_underspec a b = Mk (add_underspec (v a) (v b))
let add_mod a b = Mk (add_mod (v a) (v b))
let sub a b = Mk (sub (v a) (v b))
let sub_underspec a b = Mk (sub_underspec (v a) (v b))
let sub_mod a b = Mk (sub_mod (v a) (v b))
let mul a b = Mk (mul (v a) (v b))
let mul_underspec a b = Mk (mul_underspec (v a) (v b))
let mul_mod a b = Mk (mul_mod (v a) (v b))
let div a b = Mk (div (v a) (v b))
let rem a b = Mk (mod (v a) (v b))
let logand x y = Mk (logand (v x) (v y))
let logxor x y = Mk (logxor (v x) (v y))
let logor x y = Mk (logor (v x) (v y))
let lognot x = Mk (lognot (v x))
let shift_right a s = Mk (shift_right (v a) (UInt32.v s))
#push-options "--z3rlimit 80 --fuel 1" //AR: working around the interleaving semantics of pragmas
let shift_left a s = Mk (shift_left (v a) (UInt32.v s)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked"
],
"interface_file": true,
"source_file": "FStar.UInt8.fst"
} | [
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 1,
"initial_ifuel": 1,
"max_fuel": 1,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 80,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | a: FStar.UInt8.t -> b: FStar.UInt8.t
-> FStar.Pervasives.Lemma
(ensures
FStar.UInt.msb (FStar.UInt8.v a) = FStar.UInt.msb (FStar.UInt8.v b) ==>
(FStar.UInt8.v a < FStar.UInt8.v b <==>
FStar.UInt.msb (FStar.UInt8.v (FStar.UInt8.sub_mod a b)))) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"FStar.UInt8.t",
"FStar.UInt.from_vec_propriety",
"FStar.UInt8.n",
"FStar.UInt.to_vec",
"FStar.UInt8.v",
"FStar.UInt8.sub_mod",
"Prims.unit"
] | [] | true | false | true | false | false | let lemma_sub_msbs a b =
| from_vec_propriety (to_vec (v a)) 1;
from_vec_propriety (to_vec (v b)) 1;
from_vec_propriety (to_vec (v (sub_mod a b))) 1 | false |
Hacl.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.carry_wide | val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime) | val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime) | let carry_wide f =
let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc (==) {
SD.bn_v out % P.prime;
(==) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
(==) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
(==) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 160,
"start_col": 0,
"start_line": 138
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime)
let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
}
val carry_wide: f:felem_wide ->
Pure felem
(requires True)
(ensures fun out ->
SD.bn_v out % P.prime == SD.bn_v f % P.prime) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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.Curve25519.Field64.Core.felem_wide
-> Prims.Pure Hacl.Spec.Curve25519.Field64.Core.felem | Prims.Pure | [] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem_wide",
"Lib.IntTypes.uint64",
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Prims.unit",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Lib.IntTypes.U64",
"Spec.Curve25519.prime",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"FStar.Calc.calc_step",
"Lib.Sequence.concat",
"Hacl.Spec.Bignum.Definitions.limb",
"Lib.Sequence.sub",
"Prims.op_Addition",
"FStar.Mul.op_Star",
"Prims.pow2",
"Lib.IntTypes.v",
"Lib.IntTypes.SEC",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"Hacl.Spec.Curve25519.Field64.Core.carry_pass_lemma",
"Prims.squash",
"Hacl.Spec.Curve25519.Field64.Lemmas.lemma_mul_pow256_add",
"Hacl.Spec.Bignum.Definitions.bn_concat_lemma",
"Lib.Sequence.eq_intro",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.carry_pass",
"Hacl.Spec.Curve25519.Field64.Lemmas.carry_wide_bound",
"Hacl.Spec.Bignum.Definitions.bn_eval_bound",
"Prims._assert",
"FStar.Pervasives.Native.tuple2",
"Lib.IntTypes.int_t",
"Hacl.Spec.Curve25519.Field64.Core.mul1_add",
"Lib.IntTypes.u64"
] | [] | false | false | false | false | false | let carry_wide f =
| let c, r0 = mul1_add (sub f 4 4) (u64 38) (sub f 0 4) in
assert (SD.bn_v r0 + v c * pow2 256 == SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38);
SD.bn_eval_bound (sub f 0 4) 4;
SD.bn_eval_bound (sub f 4 4) 4;
SD.bn_eval_bound r0 4;
Lemmas.carry_wide_bound (SD.bn_v r0) (v c) (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4));
let out = carry_pass r0 c in
calc ( == ) {
SD.bn_v out % P.prime;
( == ) { carry_pass_lemma r0 c }
(SD.bn_v r0 + v c * pow2 256) % P.prime;
( == ) { () }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * 38) % P.prime;
( == ) { Lemmas.lemma_mul_pow256_add (SD.bn_v (sub f 0 4)) (SD.bn_v (sub f 4 4)) }
(SD.bn_v (sub f 0 4) + SD.bn_v (sub f 4 4) * pow2 256) % P.prime;
( == ) { SD.bn_concat_lemma (sub f 0 4) (sub f 4 4) }
SD.bn_v (concat (sub f 0 4) (sub f 4 4)) % P.prime;
( == ) { eq_intro f (concat (sub f 0 4) (sub f 4 4)) }
SD.bn_v f % P.prime;
};
out | false |
Hacl.Spec.Curve25519.Field64.Core.fst | Hacl.Spec.Curve25519.Field64.Core.carry_pass_lemma | val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime) | val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime) | let carry_pass_lemma f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
SD.bn_upd_eval r b1 0;
calc (==) {
SD.bn_v out % P.prime;
(==) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[0] + v b1) % P.prime;
(==) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[0] + (v r.[0] + v c * 38)) % P.prime;
(==) { }
(SD.bn_v r + v c * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
(==) { }
(SD.bn_v f + v cin * 38) % P.prime;
(==) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
} | {
"file_name": "code/curve25519/Hacl.Spec.Curve25519.Field64.Core.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 129,
"start_col": 0,
"start_line": 109
} | module Hacl.Spec.Curve25519.Field64.Core
open FStar.Mul
open Lib.IntTypes
open Lib.Sequence
open Hacl.Spec.Curve25519.Field64.Definition
module P = Spec.Curve25519
module CL = Hacl.Spec.Curve25519.Field64.Lemmas
module SD = Hacl.Spec.Bignum.Definitions
module SB = Hacl.Spec.Bignum
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
unfold
let felem = SD.lbignum U64 4
unfold
let felem_wide = SD.lbignum U64 8
// let as_felem4 (e:felem) : felem4 =
// (e.[0], e.[1], e.[2], e.[3])
// let as_nat (e:felem) = as_nat4 (as_felem4 e)
val add1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin)
let add1 f cin =
let (c, out) = SB.bn_add1 f cin in
SB.bn_add1_lemma f cin;
(c, out)
val sub1: f:felem -> cin:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) -> v c <= 1 /\
SD.bn_v r - v c * pow2 256 == SD.bn_v f - v cin)
let sub1 f cin =
let c, out = SB.bn_sub1 f cin in
SB.bn_sub1_lemma f cin;
c, out
val mul1: f:felem -> u:uint64 ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f * v u)
let mul1 f u =
let c, out = SB.bn_mul1 f u in
SB.bn_mul1_lemma f u;
c, out
val mul1_add: f1:felem -> u2:uint64 -> f3:felem ->
Pure (uint64 & felem)
(requires True)
(ensures fun (c, r) ->
SD.bn_v r + v c * pow2 256 == SD.bn_v f3 + SD.bn_v f1 * v u2)
let mul1_add f1 u2 f3 =
let c, out = SB.bn_mul1_lshift_add f1 u2 0 f3 in
SB.bn_mul1_lshift_add_lemma f1 u2 0 f3;
c, out
val carry_pass: f:felem -> cin:uint64 -> felem
let carry_pass f cin =
let c, r = add1 f (cin *. u64 38) in
let b1 = r.[0] +. c *. u64 38 in
let out = r.[0] <- b1 in
out
val lemma_add1_carry: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
v b1 == v r.[0] + v c * 38)
let lemma_add1_carry f cin =
let c, r = add1 f (cin *! u64 38) in
let b1 = r.[0] +. c *. u64 38 in
assert (SD.bn_v r + v c * pow2 256 == SD.bn_v f + v cin * 38);
SD.bn_eval_split_i f 1;
SD.bn_eval1 (slice f 0 1);
//assert (SD.bn_v f == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4));
SD.bn_eval_split_i r 1;
SD.bn_eval1 (slice r 0 1);
assert (v r.[0] + pow2 64 * SD.bn_v (slice r 1 4) + v c * pow2 256 == v f.[0] + pow2 64 * SD.bn_v (slice f 1 4) + v cin * 38);
SD.bn_eval_bound (slice f 1 4) 3;
SD.bn_eval_bound (slice r 1 4) 3;
Math.Lemmas.pow2_plus 64 192;
assert (v r.[0] == (v f.[0] + v cin * 38) % pow2 64)
val carry_pass_lemma: f:felem -> cin:uint64{v cin * 38 < pow2 63} ->
Lemma (SD.bn_v (carry_pass f cin) % P.prime == (SD.bn_v f + v cin * pow2 256) % P.prime) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Lib.Sequence.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Spec.Curve25519.Field64.Lemmas.fst.checked",
"Hacl.Spec.Curve25519.Field64.Definition.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Spec.Bignum.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.Calc.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.Spec.Curve25519.Field64.Core.fst"
} | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum",
"short_module": "SB"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "SD"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Field64.Lemmas",
"short_module": "CL"
},
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64.Definition",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Sequence",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.IntTypes",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Spec.Curve25519.Field64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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.Curve25519.Field64.Core.felem ->
cin: Lib.IntTypes.uint64{Lib.IntTypes.v cin * 38 < Prims.pow2 63}
-> FStar.Pervasives.Lemma
(ensures
Hacl.Spec.Bignum.Definitions.bn_v (Hacl.Spec.Curve25519.Field64.Core.carry_pass f cin) %
Spec.Curve25519.prime ==
(Hacl.Spec.Bignum.Definitions.bn_v f + Lib.IntTypes.v cin * Prims.pow2 256) %
Spec.Curve25519.prime) | FStar.Pervasives.Lemma | [
"lemma"
] | [] | [
"Hacl.Spec.Curve25519.Field64.Core.felem",
"Lib.IntTypes.uint64",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.Mul.op_Star",
"Lib.IntTypes.v",
"Lib.IntTypes.U64",
"Lib.IntTypes.SEC",
"Prims.pow2",
"FStar.Calc.calc_finish",
"Prims.int",
"Prims.eq2",
"Prims.op_Modulus",
"Hacl.Spec.Bignum.Definitions.bn_v",
"Spec.Curve25519.prime",
"Prims.op_Addition",
"Prims.Cons",
"FStar.Preorder.relation",
"Prims.Nil",
"Prims.unit",
"FStar.Calc.calc_step",
"Prims.op_Subtraction",
"Lib.Sequence.op_String_Access",
"Hacl.Spec.Bignum.Definitions.limb",
"FStar.Calc.calc_init",
"FStar.Calc.calc_pack",
"FStar.Pervasives.assert_norm",
"Prims.op_Equality",
"Prims.squash",
"Hacl.Spec.Curve25519.Field64.Core.lemma_add1_carry",
"Hacl.Spec.Curve25519.Field64.Lemmas.lemma_mul_pow256_add",
"Hacl.Spec.Bignum.Definitions.bn_upd_eval",
"Lib.Sequence.lseq",
"Prims.l_and",
"FStar.Seq.Base.seq",
"Lib.Sequence.to_seq",
"FStar.Seq.Base.upd",
"Lib.Sequence.index",
"Prims.l_Forall",
"Prims.nat",
"Prims.op_LessThanOrEqual",
"Prims.l_imp",
"Prims.op_disEquality",
"Prims.l_or",
"FStar.Seq.Base.index",
"Lib.Sequence.op_String_Assignment",
"Lib.IntTypes.int_t",
"Lib.IntTypes.op_Plus_Dot",
"Lib.IntTypes.op_Star_Dot",
"Lib.IntTypes.u64",
"FStar.Pervasives.Native.tuple2",
"Hacl.Spec.Bignum.Definitions.lbignum",
"Hacl.Spec.Curve25519.Field64.Core.add1",
"Lib.IntTypes.op_Star_Bang"
] | [] | false | false | true | false | false | let carry_pass_lemma f cin =
| let c, r = add1 f (cin *! u64 38) in
let b1 = r.[ 0 ] +. c *. u64 38 in
let out = r.[ 0 ] <- b1 in
SD.bn_upd_eval r b1 0;
calc ( == ) {
SD.bn_v out % P.prime;
( == ) { assert_norm (pow2 0 = 1) }
(SD.bn_v r - v r.[ 0 ] + v b1) % P.prime;
( == ) { lemma_add1_carry f cin }
(SD.bn_v r - v r.[ 0 ] + (v r.[ 0 ] + v c * 38)) % P.prime;
( == ) { () }
(SD.bn_v r + v c * 38) % P.prime;
( == ) { Lemmas.lemma_mul_pow256_add (SD.bn_v r) (v c) }
(SD.bn_v r + v c * pow2 256) % P.prime;
( == ) { () }
(SD.bn_v f + v cin * 38) % P.prime;
( == ) { Lemmas.lemma_mul_pow256_add (SD.bn_v f) (v cin) }
(SD.bn_v f + v cin * pow2 256) % P.prime;
} | false |
Steel.ST.Printf.fst | Steel.ST.Printf.interpret_frags | val interpret_frags (l: fragments) (acc: list frag_t) : Type u#1 | val interpret_frags (l: fragments) (acc: list frag_t) : Type u#1 | let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc) | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 39,
"end_line": 338,
"start_col": 0,
"start_line": 305
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__] | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: Steel.ST.Printf.fragments -> acc: Prims.list Steel.ST.Printf.frag_t -> Type | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.Printf.fragments",
"Prims.list",
"Steel.ST.Printf.frag_t",
"Steel.ST.Printf.lift",
"Prims.unit",
"Steel.ST.Printf.live_frags",
"Steel.Effect.Common.vprop",
"Steel.ST.Printf.base_typ",
"Steel.ST.Printf.fragment",
"Steel.ST.Printf.base_typ_as_type",
"Steel.ST.Printf.interpret_frags",
"Prims.Cons",
"FStar.Pervasives.Inr",
"Prims.string",
"Prims.dtuple2",
"Steel.ST.Printf.arg",
"Steel.ST.Printf.arg_t",
"Prims.Mkdtuple2",
"Steel.ST.Printf.Base",
"Steel.ST.Printf.Lift",
"FStar.UInt32.t",
"Steel.FractionalPermission.perm",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.Printf.lmbuffer",
"Steel.ST.Printf.Array",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"Steel.ST.Printf.Any",
"FStar.Pervasives.Mkdtuple3",
"FStar.Pervasives.Inl"
] | [
"recursion"
] | false | false | false | true | true | let rec interpret_frags (l: fragments) (acc: list frag_t) : Type u#1 =
| match l with
| [] -> lift u#0 u#1 unit -> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
x: base_typ_as_type t -> interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
l: UInt32.t ->
#p: perm ->
#v: Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b: lmbuffer (base_typ_as_type t) l
-> interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a: Type0 -> p: (a -> StTrivial unit) -> x: a
-> interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args -> interpret_frags args (Inl s :: acc) | false |
Steel.ST.Printf.fst | Steel.ST.Printf.printf' | val printf' (s: format_string) : interpret_format_string s | val printf' (s: format_string) : interpret_format_string s | let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags) | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 45,
"end_line": 510,
"start_col": 0,
"start_line": 507
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time. | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Steel.ST.Printf.format_string -> Steel.ST.Printf.interpret_format_string s | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.Printf.format_string",
"FStar.Pervasives.normalize_term",
"Steel.ST.Printf.interpret_format_string",
"Steel.ST.Printf.parse_format_string",
"Steel.ST.Printf.fragments",
"Steel.ST.Printf.aux",
"Prims.Nil",
"Steel.ST.Printf.frag_t",
"Steel.ST.Printf.print_frags"
] | [] | false | false | false | false | false | let printf' (s: format_string) : interpret_format_string s =
| normalize_term (match parse_format_string s with | Some frags -> aux frags [] print_frags) | false |
Steel.ST.Printf.fst | Steel.ST.Printf.skip' | val skip' (s: format_string) : interpret_format_string s | val skip' (s: format_string) : interpret_format_string s | let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> noop ())) | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 52,
"end_line": 539,
"start_col": 0,
"start_line": 536
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance. | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | s: Steel.ST.Printf.format_string -> Steel.ST.Printf.interpret_format_string s | Prims.Tot | [
"total"
] | [] | [
"Steel.ST.Printf.format_string",
"FStar.Pervasives.normalize_term",
"Steel.ST.Printf.interpret_format_string",
"Steel.ST.Printf.parse_format_string",
"Steel.ST.Printf.fragments",
"Steel.ST.Printf.aux",
"Prims.Nil",
"Steel.ST.Printf.frag_t",
"Prims.list",
"Steel.ST.Util.noop",
"FStar.Ghost.hide",
"FStar.Set.set",
"Steel.Memory.iname",
"FStar.Set.empty",
"Prims.unit"
] | [] | false | false | false | false | false | let skip' (s: format_string) : interpret_format_string s =
| normalize_term (match parse_format_string s with | Some frags -> aux frags [] (fun _ -> noop ())) | false |
Hacl.Impl.Curve25519.Finv.fst | Hacl.Impl.Curve25519.Finv.fsquare_times_inv | val fsquare_times_inv: #s:field_spec -> h:mem -> f:felem s -> Type0 | val fsquare_times_inv: #s:field_spec -> h:mem -> f:felem s -> Type0 | let fsquare_times_inv #s h f =
match s with
| M51 -> C.f51_felem_fits h f (1, 2, 1, 1, 1)
| M64 -> True | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 15,
"end_line": 26,
"start_col": 0,
"start_line": 23
} | module Hacl.Impl.Curve25519.Finv
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Curve25519.Fields
module ST = FStar.HyperStack.ST
module C = Hacl.Impl.Curve25519.Fields.Core
module S = Hacl.Spec.Curve25519.Finv
module P = Spec.Curve25519
let _: squash (inversion field_spec) = allow_inversion field_spec
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --record_options"
noextract | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Loops.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Curve25519.Finv.fst.checked",
"Hacl.Impl.Curve25519.Fields.Core.fsti.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"FStar.UInt32.fsti.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.Curve25519.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Finv",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"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": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 -> f: Hacl.Impl.Curve25519.Fields.Core.felem s -> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Hacl.Impl.Curve25519.Fields.Core.f51_felem_fits",
"FStar.Pervasives.Native.Mktuple5",
"Prims.nat",
"Prims.l_True"
] | [] | false | false | false | false | true | let fsquare_times_inv #s h f =
| match s with
| M51 -> C.f51_felem_fits h f (1, 2, 1, 1, 1)
| M64 -> True | false |
Hacl.Impl.Curve25519.Finv.fst | Hacl.Impl.Curve25519.Finv.fmuls_pre | val fmuls_pre: #s:field_spec -> h:mem -> f1:felem s -> f2:felem s -> Type0 | val fmuls_pre: #s:field_spec -> h:mem -> f1:felem s -> f2:felem s -> Type0 | let fmuls_pre #s h f1 f2 =
match s with
| M51 -> f51_felem_fits h f1 (1, 2, 1, 1, 1) /\ f51_felem_fits h f2 (1, 2, 1, 1, 1)
| M64 -> True | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 15,
"end_line": 55,
"start_col": 0,
"start_line": 52
} | module Hacl.Impl.Curve25519.Finv
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Curve25519.Fields
module ST = FStar.HyperStack.ST
module C = Hacl.Impl.Curve25519.Fields.Core
module S = Hacl.Spec.Curve25519.Finv
module P = Spec.Curve25519
let _: squash (inversion field_spec) = allow_inversion field_spec
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --record_options"
noextract
val fsquare_times_inv: #s:field_spec -> h:mem -> f:felem s -> Type0
let fsquare_times_inv #s h f =
match s with
| M51 -> C.f51_felem_fits h f (1, 2, 1, 1, 1)
| M64 -> True
val fsqr_s:
#s:field_spec
-> out:felem s
-> f1:felem s
-> tmp:felem_wide s
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h tmp /\
(disjoint out f1 \/ out == f1) /\
(disjoint out tmp) /\
disjoint tmp f1 /\
fsquare_times_inv h f1)
(ensures fun h0 _ h1 ->
modifies (loc out |+| loc tmp) h0 h1 /\
fsquare_times_inv h1 out /\
feval h1 out == P.fmul (feval h0 f1) (feval h0 f1))
[@ Meta.Attribute.inline_ ]
let fsqr_s #s out f1 tmp =
C.fsqr #s out f1 tmp
noextract | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Loops.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Curve25519.Finv.fst.checked",
"Hacl.Impl.Curve25519.Fields.Core.fsti.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"FStar.UInt32.fsti.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.Curve25519.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Finv",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"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": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 ->
f1: Hacl.Impl.Curve25519.Fields.Core.felem s ->
f2: Hacl.Impl.Curve25519.Fields.Core.felem s
-> Type0 | Prims.Tot | [
"total"
] | [] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"FStar.Monotonic.HyperStack.mem",
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Prims.l_and",
"Hacl.Impl.Curve25519.Fields.Core.f51_felem_fits",
"FStar.Pervasives.Native.Mktuple5",
"Prims.nat",
"Prims.l_True"
] | [] | false | false | false | false | true | let fmuls_pre #s h f1 f2 =
| match s with
| M51 -> f51_felem_fits h f1 (1, 2, 1, 1, 1) /\ f51_felem_fits h f2 (1, 2, 1, 1, 1)
| M64 -> True | false |
Hacl.Impl.Curve25519.Finv.fst | Hacl.Impl.Curve25519.Finv.fsqr_s | val fsqr_s:
#s:field_spec
-> out:felem s
-> f1:felem s
-> tmp:felem_wide s
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h tmp /\
(disjoint out f1 \/ out == f1) /\
(disjoint out tmp) /\
disjoint tmp f1 /\
fsquare_times_inv h f1)
(ensures fun h0 _ h1 ->
modifies (loc out |+| loc tmp) h0 h1 /\
fsquare_times_inv h1 out /\
feval h1 out == P.fmul (feval h0 f1) (feval h0 f1)) | val fsqr_s:
#s:field_spec
-> out:felem s
-> f1:felem s
-> tmp:felem_wide s
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h tmp /\
(disjoint out f1 \/ out == f1) /\
(disjoint out tmp) /\
disjoint tmp f1 /\
fsquare_times_inv h f1)
(ensures fun h0 _ h1 ->
modifies (loc out |+| loc tmp) h0 h1 /\
fsquare_times_inv h1 out /\
feval h1 out == P.fmul (feval h0 f1) (feval h0 f1)) | let fsqr_s #s out f1 tmp =
C.fsqr #s out f1 tmp | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 22,
"end_line": 47,
"start_col": 0,
"start_line": 46
} | module Hacl.Impl.Curve25519.Finv
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Curve25519.Fields
module ST = FStar.HyperStack.ST
module C = Hacl.Impl.Curve25519.Fields.Core
module S = Hacl.Spec.Curve25519.Finv
module P = Spec.Curve25519
let _: squash (inversion field_spec) = allow_inversion field_spec
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --record_options"
noextract
val fsquare_times_inv: #s:field_spec -> h:mem -> f:felem s -> Type0
let fsquare_times_inv #s h f =
match s with
| M51 -> C.f51_felem_fits h f (1, 2, 1, 1, 1)
| M64 -> True
val fsqr_s:
#s:field_spec
-> out:felem s
-> f1:felem s
-> tmp:felem_wide s
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h tmp /\
(disjoint out f1 \/ out == f1) /\
(disjoint out tmp) /\
disjoint tmp f1 /\
fsquare_times_inv h f1)
(ensures fun h0 _ h1 ->
modifies (loc out |+| loc tmp) h0 h1 /\
fsquare_times_inv h1 out /\
feval h1 out == P.fmul (feval h0 f1) (feval h0 f1)) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Loops.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Curve25519.Finv.fst.checked",
"Hacl.Impl.Curve25519.Fields.Core.fsti.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"FStar.UInt32.fsti.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.Curve25519.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Finv",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"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": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
out: Hacl.Impl.Curve25519.Fields.Core.felem s ->
f1: Hacl.Impl.Curve25519.Fields.Core.felem s ->
tmp: Hacl.Impl.Curve25519.Fields.Core.felem_wide s
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Hacl.Impl.Curve25519.Fields.Core.felem_wide",
"Hacl.Impl.Curve25519.Fields.Core.fsqr",
"Prims.unit"
] | [] | false | true | false | false | false | let fsqr_s #s out f1 tmp =
| C.fsqr #s out f1 tmp | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_rl_f | val exp_rl_f : k: Lib.Exponentiation.Definition.comm_monoid t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
i: Prims.nat{i < bBits} ->
_: (t * t)
-> t * t | let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c) | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 17,
"start_col": 0,
"start_line": 14
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
i: Prims.nat{i < bBits} ->
_: (t * t)
-> t * t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Exponentiation.Definition.mul",
"Prims.op_Equality",
"Prims.int",
"Lib.Exponentiation.get_ith_bit",
"Prims.bool"
] | [] | false | false | false | false | false | let exp_rl_f
(#t: Type)
(k: comm_monoid t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(i: nat{i < bBits})
(acc, c: tuple2 t t)
: tuple2 t t =
| let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c) | false |
|
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_rl | val exp_rl (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits}) : t | val exp_rl (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits}) : t | let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 21,
"start_col": 0,
"start_line": 19
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a: t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits}
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Pervasives.Native.tuple2",
"Lib.LoopCombinators.repeati",
"Lib.Exponentiation.exp_rl_f",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Exponentiation.Definition.one"
] | [] | false | false | false | false | false | let exp_rl (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits}) : t =
| let acc, c = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_lr | val exp_lr (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits}) : t | val exp_lr (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits}) : t | let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 48,
"end_line": 34,
"start_col": 0,
"start_line": 33
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a: t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits}
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Lib.LoopCombinators.repeati",
"Lib.Exponentiation.exp_lr_f",
"Lib.Exponentiation.Definition.one"
] | [] | false | false | false | false | false | let exp_lr (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits}) : t =
| Loops.repeati bBits (exp_lr_f k a bBits b) one | false |
Hacl.Impl.Curve25519.Finv.fst | Hacl.Impl.Curve25519.Finv.fmul_s | val fmul_s:
#s:field_spec
-> out:felem s
-> f1:felem s
-> f2:felem s
-> tmp:felem_wide2 s
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h f2 /\ live h tmp /\
(disjoint out f1 \/ out == f1) /\
(disjoint out f2 \/ out == f2) /\
(disjoint out tmp) /\
(disjoint f1 f2 \/ f1 == f2) /\
disjoint f1 tmp /\
disjoint f2 tmp /\
fmuls_pre h f1 f2)
(ensures fun h0 _ h1 ->
modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\
feval h1 out == P.fmul (feval h0 f1) (feval h0 f2)) | val fmul_s:
#s:field_spec
-> out:felem s
-> f1:felem s
-> f2:felem s
-> tmp:felem_wide2 s
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h f2 /\ live h tmp /\
(disjoint out f1 \/ out == f1) /\
(disjoint out f2 \/ out == f2) /\
(disjoint out tmp) /\
(disjoint f1 f2 \/ f1 == f2) /\
disjoint f1 tmp /\
disjoint f2 tmp /\
fmuls_pre h f1 f2)
(ensures fun h0 _ h1 ->
modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\
feval h1 out == P.fmul (feval h0 f1) (feval h0 f2)) | let fmul_s #s out f1 f2 tmp =
C.fmul #s out f1 f2 tmp | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 25,
"end_line": 79,
"start_col": 0,
"start_line": 78
} | module Hacl.Impl.Curve25519.Finv
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Curve25519.Fields
module ST = FStar.HyperStack.ST
module C = Hacl.Impl.Curve25519.Fields.Core
module S = Hacl.Spec.Curve25519.Finv
module P = Spec.Curve25519
let _: squash (inversion field_spec) = allow_inversion field_spec
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --record_options"
noextract
val fsquare_times_inv: #s:field_spec -> h:mem -> f:felem s -> Type0
let fsquare_times_inv #s h f =
match s with
| M51 -> C.f51_felem_fits h f (1, 2, 1, 1, 1)
| M64 -> True
val fsqr_s:
#s:field_spec
-> out:felem s
-> f1:felem s
-> tmp:felem_wide s
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h tmp /\
(disjoint out f1 \/ out == f1) /\
(disjoint out tmp) /\
disjoint tmp f1 /\
fsquare_times_inv h f1)
(ensures fun h0 _ h1 ->
modifies (loc out |+| loc tmp) h0 h1 /\
fsquare_times_inv h1 out /\
feval h1 out == P.fmul (feval h0 f1) (feval h0 f1))
[@ Meta.Attribute.inline_ ]
let fsqr_s #s out f1 tmp =
C.fsqr #s out f1 tmp
noextract
val fmuls_pre: #s:field_spec -> h:mem -> f1:felem s -> f2:felem s -> Type0
let fmuls_pre #s h f1 f2 =
match s with
| M51 -> f51_felem_fits h f1 (1, 2, 1, 1, 1) /\ f51_felem_fits h f2 (1, 2, 1, 1, 1)
| M64 -> True
val fmul_s:
#s:field_spec
-> out:felem s
-> f1:felem s
-> f2:felem s
-> tmp:felem_wide2 s
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h f2 /\ live h tmp /\
(disjoint out f1 \/ out == f1) /\
(disjoint out f2 \/ out == f2) /\
(disjoint out tmp) /\
(disjoint f1 f2 \/ f1 == f2) /\
disjoint f1 tmp /\
disjoint f2 tmp /\
fmuls_pre h f1 f2)
(ensures fun h0 _ h1 ->
modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\
feval h1 out == P.fmul (feval h0 f1) (feval h0 f2)) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Loops.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Curve25519.Finv.fst.checked",
"Hacl.Impl.Curve25519.Fields.Core.fsti.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"FStar.UInt32.fsti.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.Curve25519.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Finv",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"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": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
out: Hacl.Impl.Curve25519.Fields.Core.felem s ->
f1: Hacl.Impl.Curve25519.Fields.Core.felem s ->
f2: Hacl.Impl.Curve25519.Fields.Core.felem s ->
tmp: Hacl.Impl.Curve25519.Fields.Core.felem_wide2 s
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Hacl.Impl.Curve25519.Fields.Core.felem_wide2",
"Hacl.Impl.Curve25519.Fields.Core.fmul",
"Prims.unit"
] | [] | false | true | false | false | false | let fmul_s #s out f1 f2 tmp =
| C.fmul #s out f1 f2 tmp | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.get_ith_bit | val get_ith_bit : bBits: Prims.nat -> b: Prims.nat{b < Prims.pow2 bBits} -> i: Prims.nat{i < bBits} -> Prims.int | let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2 | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 11,
"start_col": 0,
"start_line": 10
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | bBits: Prims.nat -> b: Prims.nat{b < Prims.pow2 bBits} -> i: Prims.nat{i < bBits} -> Prims.int | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Modulus",
"Prims.op_Division",
"Prims.int"
] | [] | false | false | false | false | false | let get_ith_bit (bBits: nat) (b: nat{b < pow2 bBits}) (i: nat{i < bBits}) =
| b / pow2 i % 2 | false |
|
Lib.Exponentiation.fsti | Lib.Exponentiation.cswap | val cswap (#t: Type) (sw: nat) (r0 r1: t) : tuple2 t t | val cswap (#t: Type) (sw: nat) (r0 r1: t) : tuple2 t t | let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1) | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 39,
"end_line": 57,
"start_col": 0,
"start_line": 56
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | sw: Prims.nat -> r0: t -> r1: t -> t * t | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.op_Equality",
"Prims.int",
"FStar.Pervasives.Native.Mktuple2",
"Prims.bool",
"FStar.Pervasives.Native.tuple2"
] | [] | false | false | false | true | false | let cswap (#t: Type) (sw: nat) (r0 r1: t) : tuple2 t t =
| if sw = 1 then (r1, r0) else (r0, r1) | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_mont_ladder | val exp_mont_ladder (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits}) : t | val exp_mont_ladder (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits}) : t | let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0 | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 49,
"start_col": 0,
"start_line": 47
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a: t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits}
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Pervasives.Native.tuple2",
"Lib.LoopCombinators.repeati",
"Lib.Exponentiation.exp_mont_ladder_f",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Exponentiation.Definition.one"
] | [] | false | false | false | false | false | let exp_mont_ladder (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits}) : t =
| let r0, r1 = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0 | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_mont_ladder_swap2 | val exp_mont_ladder_swap2 (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits})
: t | val exp_mont_ladder_swap2 (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits})
: t | let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0 | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 69,
"start_col": 0,
"start_line": 67
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a: t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits}
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Pervasives.Native.tuple2",
"Lib.LoopCombinators.repeati",
"Lib.Exponentiation.exp_mont_ladder_swap2_f",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Exponentiation.Definition.one"
] | [] | false | false | false | false | false | let exp_mont_ladder_swap2 (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits})
: t =
| let r0, r1 = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0 | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_lr_f | val exp_lr_f
(#t: Type)
(k: comm_monoid t)
(a: t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(i: nat{i < bBits})
(acc: t)
: t | val exp_lr_f
(#t: Type)
(k: comm_monoid t)
(a: t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(i: nat{i < bBits})
(acc: t)
: t | let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 31,
"start_col": 0,
"start_line": 28
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a: t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
i: Prims.nat{i < bBits} ->
acc: t
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.op_Equality",
"Prims.int",
"Lib.Exponentiation.get_ith_bit",
"Prims.op_Subtraction",
"Prims.bool",
"Lib.Exponentiation.Definition.mul"
] | [] | false | false | false | false | false | let exp_lr_f
(#t: Type)
(k: comm_monoid t)
(a: t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(i: nat{i < bBits})
(acc: t)
: t =
| let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_mont_ladder_f | val exp_mont_ladder_f : k: Lib.Exponentiation.Definition.comm_monoid t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
i: Prims.nat{i < bBits} ->
_: (t * t)
-> t * t | let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1) | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 45,
"start_col": 0,
"start_line": 41
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
i: Prims.nat{i < bBits} ->
_: (t * t)
-> t * t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Pervasives.Native.tuple2",
"Prims.op_Equality",
"Prims.int",
"Lib.Exponentiation.get_ith_bit",
"Prims.op_Subtraction",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Exponentiation.Definition.mul",
"Prims.bool"
] | [] | false | false | false | false | false | let exp_mont_ladder_f
(#t: Type)
(k: comm_monoid t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(i: nat{i < bBits})
(r0, r1: tuple2 t t)
: tuple2 t t =
| if (get_ith_bit bBits b (bBits - 1 - i) = 0) then (mul r0 r0, mul r1 r0) else (mul r0 r1, mul r1 r1) | false |
|
Steel.ST.Printf.fst | Steel.ST.Printf.test2_printf | val test2_printf (x: (int * int)) (print_pair: ((int * int) -> StTrivial unit))
: STT unit emp (fun _ -> emp) | val test2_printf (x: (int * int)) (print_pair: ((int * int) -> StTrivial unit))
: STT unit emp (fun _ -> emp) | let test2_printf (x:(int * int)) (print_pair:(int * int) -> StTrivial unit)
: STT unit emp (fun _ -> emp)
= printf "Hello pair %a" print_pair x done | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 44,
"end_line": 570,
"start_col": 0,
"start_line": 568
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance.
noextract inline_for_extraction
let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> noop ()))
noextract inline_for_extraction
val skip : s:normal format_string -> normal (interpret_format_string s)
let skip = intro_normal_f #format_string interpret_format_string skip'
/// `test`: A small test function
/// Running `fstar --codegen OCaml Steel.ST.Printf.fst --extract Steel.ST.Printf`
/// produces the following for the body of this function
/// ```
/// print_string "Hello ";
/// print_bool true;
/// print_string " Steel.ST ";
/// print_u64 m;
/// print_string " Printf ";
/// print_lmbuffer_bool l x () ();
/// print_string " ";
/// print_string "bye"
/// ```
let test_printf (m:UInt64.t) (l:UInt32.t) (x:A.array bool {A.length x == U32.v l}) (v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v)
= printf "Hello %b Steel.ST %uL Printf %xb %s"
true //%b boolean
m //%uL u64
l x //%xb (buffer bool)
"bye"
done //dummy universe coercion | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
x: (Prims.int * Prims.int) ->
print_pair: (_: (Prims.int * Prims.int) -> Steel.ST.Printf.StTrivial Prims.unit)
-> Steel.ST.Effect.STT Prims.unit | Steel.ST.Effect.STT | [] | [] | [
"FStar.Pervasives.Native.tuple2",
"Prims.int",
"Prims.unit",
"Steel.ST.Printf.printf",
"Steel.ST.Printf.done",
"Steel.Effect.Common.emp",
"Steel.Effect.Common.vprop"
] | [] | false | true | false | false | false | let test2_printf (x: (int * int)) (print_pair: ((int * int) -> StTrivial unit))
: STT unit emp (fun _ -> emp) =
| printf "Hello pair %a" print_pair x done | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_mont_ladder_swap | val exp_mont_ladder_swap (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits})
: t | val exp_mont_ladder_swap (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits})
: t | let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0 | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 4,
"end_line": 86,
"start_col": 0,
"start_line": 83
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a: t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits}
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Pervasives.Native.tuple2",
"Lib.Exponentiation.cswap",
"FStar.Pervasives.Native.tuple3",
"Lib.LoopCombinators.repeati",
"Lib.Exponentiation.exp_mont_ladder_swap_f",
"FStar.Pervasives.Native.Mktuple3",
"Lib.Exponentiation.Definition.one"
] | [] | false | false | false | false | false | let exp_mont_ladder_swap (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits})
: t =
| let r0, r1, sw = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let r0, r1 = cswap sw r0 r1 in
r0 | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_pow2 | val exp_pow2 (#t: Type) (k: comm_monoid t) (a: t) (b: nat) : t | val exp_pow2 (#t: Type) (k: comm_monoid t) (a: t) (b: nat) : t | let exp_pow2 (#t:Type) (k:comm_monoid t) (a:t) (b:nat) : t =
Loops.repeat b (sqr k) a | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 94,
"start_col": 0,
"start_line": 93
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit)
let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0
val exp_mont_ladder_swap_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap k a bBits b == exp_mont_ladder k a bBits b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | k: Lib.Exponentiation.Definition.comm_monoid t -> a: t -> b: Prims.nat -> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Lib.LoopCombinators.repeat",
"Lib.Exponentiation.Definition.sqr"
] | [] | false | false | false | true | false | let exp_pow2 (#t: Type) (k: comm_monoid t) (a: t) (b: nat) : t =
| Loops.repeat b (sqr k) a | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_mont_ladder_swap2_f | val exp_mont_ladder_swap2_f : k: Lib.Exponentiation.Definition.comm_monoid t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
i: Prims.nat{i < bBits} ->
_: (t * t)
-> t * t | let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1) | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 10,
"end_line": 65,
"start_col": 0,
"start_line": 60
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
i: Prims.nat{i < bBits} ->
_: (t * t)
-> t * t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Exponentiation.cswap",
"Lib.Exponentiation.Definition.mul",
"Prims.int",
"Lib.Exponentiation.get_ith_bit",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let exp_mont_ladder_swap2_f
(#t: Type)
(k: comm_monoid t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(i: nat{i < bBits})
(r0, r1: tuple2 t t)
: tuple2 t t =
| let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1) | false |
|
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_mont_ladder_swap_f | val exp_mont_ladder_swap_f : k: Lib.Exponentiation.Definition.comm_monoid t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
i: Prims.nat{i < bBits} ->
_: ((t * t) * Prims.nat)
-> (t * t) * Prims.nat | let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit) | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 15,
"end_line": 81,
"start_col": 0,
"start_line": 76
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
i: Prims.nat{i < bBits} ->
_: ((t * t) * Prims.nat)
-> (t * t) * Prims.nat | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"FStar.Pervasives.Native.tuple3",
"FStar.Pervasives.Native.Mktuple3",
"FStar.Pervasives.Native.tuple2",
"FStar.Pervasives.Native.Mktuple2",
"Lib.Exponentiation.Definition.mul",
"Lib.Exponentiation.cswap",
"Prims.int",
"Prims.op_Modulus",
"Prims.op_Addition",
"Lib.Exponentiation.get_ith_bit",
"Prims.op_Subtraction"
] | [] | false | false | false | false | false | let exp_mont_ladder_swap_f
(#t: Type)
(k: comm_monoid t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(i: nat{i < bBits})
(r0, r1, privbit: tuple3 t t nat)
: tuple3 t t nat =
| let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit) | false |
|
Lib.Exponentiation.fsti | Lib.Exponentiation.get_ith_lbits | val get_ith_lbits : bBits: Prims.nat -> b: Prims.nat{b < Prims.pow2 bBits} -> i: Prims.nat{i < bBits} -> l: Prims.pos
-> Prims.int | let get_ith_lbits (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (l:pos) =
b / pow2 i % pow2 l | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 101,
"start_col": 0,
"start_line": 100
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit)
let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0
val exp_mont_ladder_swap_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap k a bBits b == exp_mont_ladder k a bBits b)
// a fixed window method
let exp_pow2 (#t:Type) (k:comm_monoid t) (a:t) (b:nat) : t =
Loops.repeat b (sqr k) a
val exp_pow2_lemma: #t:Type -> k:comm_monoid t -> a:t -> b:nat ->
Lemma (exp_pow2 k a b == pow k a (pow2 b)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | bBits: Prims.nat -> b: Prims.nat{b < Prims.pow2 bBits} -> i: Prims.nat{i < bBits} -> l: Prims.pos
-> Prims.int | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Prims.op_Modulus",
"Prims.op_Division",
"Prims.int"
] | [] | false | false | false | false | false | let get_ith_lbits (bBits: nat) (b: nat{b < pow2 bBits}) (i: nat{i < bBits}) (l: pos) =
| b / pow2 i % pow2 l | false |
|
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_fw_acc0 | val exp_fw_acc0
(#t: Type)
(k: comm_monoid t)
(a: t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(l: pos{bBits % l <> 0})
: t | val exp_fw_acc0
(#t: Type)
(k: comm_monoid t)
(a: t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(l: pos{bBits % l <> 0})
: t | let exp_fw_acc0 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos{bBits % l <> 0}) : t =
let bits_c = get_ith_lbits bBits b (bBits / l * l) l in
pow k a bits_c | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 16,
"end_line": 119,
"start_col": 0,
"start_line": 117
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit)
let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0
val exp_mont_ladder_swap_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap k a bBits b == exp_mont_ladder k a bBits b)
// a fixed window method
let exp_pow2 (#t:Type) (k:comm_monoid t) (a:t) (b:nat) : t =
Loops.repeat b (sqr k) a
val exp_pow2_lemma: #t:Type -> k:comm_monoid t -> a:t -> b:nat ->
Lemma (exp_pow2 k a b == pow k a (pow2 b))
let get_ith_lbits (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (l:pos) =
b / pow2 i % pow2 l
let get_bits_l (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) : r:nat{r < pow2 l} =
Math.Lemmas.lemma_mult_le_left l (i + 1) (bBits / l);
assert (l * (i + 1) <= l * (bBits / l));
get_ith_lbits bBits b (bBits - bBits % l - l * i - l) l
let mul_acc_pow_a_bits_l (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let bits_l = get_bits_l bBits b l i in
mul acc (pow k a bits_l)
let exp_fw_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let acc1 = exp_pow2 k acc l in
mul_acc_pow_a_bits_l k a bBits b l i acc1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a: t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
l: Prims.pos{bBits % l <> 0}
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Prims.op_disEquality",
"Prims.int",
"Prims.op_Modulus",
"Lib.Exponentiation.Definition.pow",
"Lib.Exponentiation.get_ith_lbits",
"FStar.Mul.op_Star",
"Prims.op_Division"
] | [] | false | false | false | false | false | let exp_fw_acc0
(#t: Type)
(k: comm_monoid t)
(a: t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(l: pos{bBits % l <> 0})
: t =
| let bits_c = get_ith_lbits bBits b ((bBits / l) * l) l in
pow k a bits_c | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_fw | val exp_fw (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits}) (l: pos) : t | val exp_fw (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits}) (l: pos) : t | let exp_fw (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) : t =
let acc0 = if bBits % l = 0 then one else exp_fw_acc0 k a bBits b l in
let res = Loops.repeati (bBits / l) (exp_fw_f k a bBits b l) acc0 in
res | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 124,
"start_col": 0,
"start_line": 121
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit)
let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0
val exp_mont_ladder_swap_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap k a bBits b == exp_mont_ladder k a bBits b)
// a fixed window method
let exp_pow2 (#t:Type) (k:comm_monoid t) (a:t) (b:nat) : t =
Loops.repeat b (sqr k) a
val exp_pow2_lemma: #t:Type -> k:comm_monoid t -> a:t -> b:nat ->
Lemma (exp_pow2 k a b == pow k a (pow2 b))
let get_ith_lbits (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (l:pos) =
b / pow2 i % pow2 l
let get_bits_l (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) : r:nat{r < pow2 l} =
Math.Lemmas.lemma_mult_le_left l (i + 1) (bBits / l);
assert (l * (i + 1) <= l * (bBits / l));
get_ith_lbits bBits b (bBits - bBits % l - l * i - l) l
let mul_acc_pow_a_bits_l (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let bits_l = get_bits_l bBits b l i in
mul acc (pow k a bits_l)
let exp_fw_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let acc1 = exp_pow2 k acc l in
mul_acc_pow_a_bits_l k a bBits b l i acc1
let exp_fw_acc0 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos{bBits % l <> 0}) : t =
let bits_c = get_ith_lbits bBits b (bBits / l * l) l in
pow k a bits_c | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a: t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
l: Prims.pos
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Lib.LoopCombinators.repeati",
"Prims.op_Division",
"Lib.Exponentiation.exp_fw_f",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Lib.Exponentiation.Definition.one",
"Prims.bool",
"Lib.Exponentiation.exp_fw_acc0"
] | [] | false | false | false | false | false | let exp_fw (#t: Type) (k: comm_monoid t) (a: t) (bBits: nat) (b: nat{b < pow2 bBits}) (l: pos) : t =
| let acc0 = if bBits % l = 0 then one else exp_fw_acc0 k a bBits b l in
let res = Loops.repeati (bBits / l) (exp_fw_f k a bBits b l) acc0 in
res | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.mul_acc_pow_a_bits_l | val mul_acc_pow_a_bits_l
(#t: Type)
(k: comm_monoid t)
(a: t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(l: pos)
(i: nat{i < bBits / l})
(acc: t)
: t | val mul_acc_pow_a_bits_l
(#t: Type)
(k: comm_monoid t)
(a: t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(l: pos)
(i: nat{i < bBits / l})
(acc: t)
: t | let mul_acc_pow_a_bits_l (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let bits_l = get_bits_l bBits b l i in
mul acc (pow k a bits_l) | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 26,
"end_line": 110,
"start_col": 0,
"start_line": 108
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit)
let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0
val exp_mont_ladder_swap_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap k a bBits b == exp_mont_ladder k a bBits b)
// a fixed window method
let exp_pow2 (#t:Type) (k:comm_monoid t) (a:t) (b:nat) : t =
Loops.repeat b (sqr k) a
val exp_pow2_lemma: #t:Type -> k:comm_monoid t -> a:t -> b:nat ->
Lemma (exp_pow2 k a b == pow k a (pow2 b))
let get_ith_lbits (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (l:pos) =
b / pow2 i % pow2 l
let get_bits_l (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) : r:nat{r < pow2 l} =
Math.Lemmas.lemma_mult_le_left l (i + 1) (bBits / l);
assert (l * (i + 1) <= l * (bBits / l));
get_ith_lbits bBits b (bBits - bBits % l - l * i - l) l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a: t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
l: Prims.pos ->
i: Prims.nat{i < bBits / l} ->
acc: t
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Prims.op_Division",
"Lib.Exponentiation.Definition.mul",
"Lib.Exponentiation.Definition.pow",
"Lib.Exponentiation.get_bits_l"
] | [] | false | false | false | false | false | let mul_acc_pow_a_bits_l
(#t: Type)
(k: comm_monoid t)
(a: t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(l: pos)
(i: nat{i < bBits / l})
(acc: t)
: t =
| let bits_l = get_bits_l bBits b l i in
mul acc (pow k a bits_l) | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.get_bits_l | val get_bits_l (bBits: nat) (b: nat{b < pow2 bBits}) (l: pos) (i: nat{i < bBits / l})
: r: nat{r < pow2 l} | val get_bits_l (bBits: nat) (b: nat{b < pow2 bBits}) (l: pos) (i: nat{i < bBits / l})
: r: nat{r < pow2 l} | let get_bits_l (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) : r:nat{r < pow2 l} =
Math.Lemmas.lemma_mult_le_left l (i + 1) (bBits / l);
assert (l * (i + 1) <= l * (bBits / l));
get_ith_lbits bBits b (bBits - bBits % l - l * i - l) l | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 57,
"end_line": 106,
"start_col": 0,
"start_line": 103
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit)
let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0
val exp_mont_ladder_swap_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap k a bBits b == exp_mont_ladder k a bBits b)
// a fixed window method
let exp_pow2 (#t:Type) (k:comm_monoid t) (a:t) (b:nat) : t =
Loops.repeat b (sqr k) a
val exp_pow2_lemma: #t:Type -> k:comm_monoid t -> a:t -> b:nat ->
Lemma (exp_pow2 k a b == pow k a (pow2 b))
let get_ith_lbits (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (l:pos) =
b / pow2 i % pow2 l | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
l: Prims.pos ->
i: Prims.nat{i < bBits / l}
-> r: Prims.nat{r < Prims.pow2 l} | Prims.Tot | [
"total"
] | [] | [
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Prims.op_Division",
"Lib.Exponentiation.get_ith_lbits",
"Prims.op_Subtraction",
"Prims.op_Modulus",
"FStar.Mul.op_Star",
"Prims.unit",
"Prims._assert",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"FStar.Math.Lemmas.lemma_mult_le_left"
] | [] | false | false | false | false | false | let get_bits_l (bBits: nat) (b: nat{b < pow2 bBits}) (l: pos) (i: nat{i < bBits / l})
: r: nat{r < pow2 l} =
| Math.Lemmas.lemma_mult_le_left l (i + 1) (bBits / l);
assert (l * (i + 1) <= l * (bBits / l));
get_ith_lbits bBits b (bBits - bBits % l - l * i - l) l | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_double_fw_f | val exp_double_fw_f
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(l: pos)
(i: nat{i < bBits / l})
(acc: t)
: t | val exp_double_fw_f
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(l: pos)
(i: nat{i < bBits / l})
(acc: t)
: t | let exp_double_fw_f (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits})
(l:pos) (i:nat{i < bBits / l}) (acc:t) : t
=
let acc1 = exp_fw_f k a2 bBits b2 l i acc in
mul_acc_pow_a_bits_l k a1 bBits b1 l i acc1 | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 45,
"end_line": 141,
"start_col": 0,
"start_line": 135
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit)
let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0
val exp_mont_ladder_swap_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap k a bBits b == exp_mont_ladder k a bBits b)
// a fixed window method
let exp_pow2 (#t:Type) (k:comm_monoid t) (a:t) (b:nat) : t =
Loops.repeat b (sqr k) a
val exp_pow2_lemma: #t:Type -> k:comm_monoid t -> a:t -> b:nat ->
Lemma (exp_pow2 k a b == pow k a (pow2 b))
let get_ith_lbits (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (l:pos) =
b / pow2 i % pow2 l
let get_bits_l (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) : r:nat{r < pow2 l} =
Math.Lemmas.lemma_mult_le_left l (i + 1) (bBits / l);
assert (l * (i + 1) <= l * (bBits / l));
get_ith_lbits bBits b (bBits - bBits % l - l * i - l) l
let mul_acc_pow_a_bits_l (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let bits_l = get_bits_l bBits b l i in
mul acc (pow k a bits_l)
let exp_fw_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let acc1 = exp_pow2 k acc l in
mul_acc_pow_a_bits_l k a bBits b l i acc1
let exp_fw_acc0 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos{bBits % l <> 0}) : t =
let bits_c = get_ith_lbits bBits b (bBits / l * l) l in
pow k a bits_c
let exp_fw (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) : t =
let acc0 = if bBits % l = 0 then one else exp_fw_acc0 k a bBits b l in
let res = Loops.repeati (bBits / l) (exp_fw_f k a bBits b l) acc0 in
res
val exp_fw_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos ->
Lemma (exp_fw k a bBits b l == pow k a b)
/// Multi-Exponentiation
// Double exponentiation [a1^b1 `mul` a2^b2]
//------------------------------------------- | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a1: t ->
bBits: Prims.nat ->
b1: Prims.nat{b1 < Prims.pow2 bBits} ->
a2: t ->
b2: Prims.nat{b2 < Prims.pow2 bBits} ->
l: Prims.pos ->
i: Prims.nat{i < bBits / l} ->
acc: t
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Prims.op_Division",
"Lib.Exponentiation.mul_acc_pow_a_bits_l",
"Lib.Exponentiation.exp_fw_f"
] | [] | false | false | false | false | false | let exp_double_fw_f
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(l: pos)
(i: nat{i < bBits / l})
(acc: t)
: t =
| let acc1 = exp_fw_f k a2 bBits b2 l i acc in
mul_acc_pow_a_bits_l k a1 bBits b1 l i acc1 | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_double_fw_acc0 | val exp_double_fw_acc0
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(l: pos{bBits % l <> 0})
: t | val exp_double_fw_acc0
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(l: pos{bBits % l <> 0})
: t | let exp_double_fw_acc0 (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits}) (l:pos{bBits % l <> 0}) : t =
let acc_a1 = exp_fw_acc0 k a1 bBits b1 l in
let acc_a2 = exp_fw_acc0 k a2 bBits b2 l in
mul acc_a1 acc_a2 | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 19,
"end_line": 148,
"start_col": 0,
"start_line": 143
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit)
let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0
val exp_mont_ladder_swap_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap k a bBits b == exp_mont_ladder k a bBits b)
// a fixed window method
let exp_pow2 (#t:Type) (k:comm_monoid t) (a:t) (b:nat) : t =
Loops.repeat b (sqr k) a
val exp_pow2_lemma: #t:Type -> k:comm_monoid t -> a:t -> b:nat ->
Lemma (exp_pow2 k a b == pow k a (pow2 b))
let get_ith_lbits (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (l:pos) =
b / pow2 i % pow2 l
let get_bits_l (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) : r:nat{r < pow2 l} =
Math.Lemmas.lemma_mult_le_left l (i + 1) (bBits / l);
assert (l * (i + 1) <= l * (bBits / l));
get_ith_lbits bBits b (bBits - bBits % l - l * i - l) l
let mul_acc_pow_a_bits_l (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let bits_l = get_bits_l bBits b l i in
mul acc (pow k a bits_l)
let exp_fw_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let acc1 = exp_pow2 k acc l in
mul_acc_pow_a_bits_l k a bBits b l i acc1
let exp_fw_acc0 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos{bBits % l <> 0}) : t =
let bits_c = get_ith_lbits bBits b (bBits / l * l) l in
pow k a bits_c
let exp_fw (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) : t =
let acc0 = if bBits % l = 0 then one else exp_fw_acc0 k a bBits b l in
let res = Loops.repeati (bBits / l) (exp_fw_f k a bBits b l) acc0 in
res
val exp_fw_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos ->
Lemma (exp_fw k a bBits b l == pow k a b)
/// Multi-Exponentiation
// Double exponentiation [a1^b1 `mul` a2^b2]
//-------------------------------------------
let exp_double_fw_f (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits})
(l:pos) (i:nat{i < bBits / l}) (acc:t) : t
=
let acc1 = exp_fw_f k a2 bBits b2 l i acc in
mul_acc_pow_a_bits_l k a1 bBits b1 l i acc1 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a1: t ->
bBits: Prims.nat ->
b1: Prims.nat{b1 < Prims.pow2 bBits} ->
a2: t ->
b2: Prims.nat{b2 < Prims.pow2 bBits} ->
l: Prims.pos{bBits % l <> 0}
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Prims.op_disEquality",
"Prims.int",
"Prims.op_Modulus",
"Lib.Exponentiation.Definition.mul",
"Lib.Exponentiation.exp_fw_acc0"
] | [] | false | false | false | false | false | let exp_double_fw_acc0
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(l: pos{bBits % l <> 0})
: t =
| let acc_a1 = exp_fw_acc0 k a1 bBits b1 l in
let acc_a2 = exp_fw_acc0 k a2 bBits b2 l in
mul acc_a1 acc_a2 | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_fw_f | val exp_fw_f
(#t: Type)
(k: comm_monoid t)
(a: t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(l: pos)
(i: nat{i < bBits / l})
(acc: t)
: t | val exp_fw_f
(#t: Type)
(k: comm_monoid t)
(a: t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(l: pos)
(i: nat{i < bBits / l})
(acc: t)
: t | let exp_fw_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let acc1 = exp_pow2 k acc l in
mul_acc_pow_a_bits_l k a bBits b l i acc1 | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 43,
"end_line": 114,
"start_col": 0,
"start_line": 112
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit)
let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0
val exp_mont_ladder_swap_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap k a bBits b == exp_mont_ladder k a bBits b)
// a fixed window method
let exp_pow2 (#t:Type) (k:comm_monoid t) (a:t) (b:nat) : t =
Loops.repeat b (sqr k) a
val exp_pow2_lemma: #t:Type -> k:comm_monoid t -> a:t -> b:nat ->
Lemma (exp_pow2 k a b == pow k a (pow2 b))
let get_ith_lbits (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (l:pos) =
b / pow2 i % pow2 l
let get_bits_l (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) : r:nat{r < pow2 l} =
Math.Lemmas.lemma_mult_le_left l (i + 1) (bBits / l);
assert (l * (i + 1) <= l * (bBits / l));
get_ith_lbits bBits b (bBits - bBits % l - l * i - l) l
let mul_acc_pow_a_bits_l (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let bits_l = get_bits_l bBits b l i in
mul acc (pow k a bits_l) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a: t ->
bBits: Prims.nat ->
b: Prims.nat{b < Prims.pow2 bBits} ->
l: Prims.pos ->
i: Prims.nat{i < bBits / l} ->
acc: t
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Prims.op_Division",
"Lib.Exponentiation.mul_acc_pow_a_bits_l",
"Lib.Exponentiation.exp_pow2"
] | [] | false | false | false | false | false | let exp_fw_f
(#t: Type)
(k: comm_monoid t)
(a: t)
(bBits: nat)
(b: nat{b < pow2 bBits})
(l: pos)
(i: nat{i < bBits / l})
(acc: t)
: t =
| let acc1 = exp_pow2 k acc l in
mul_acc_pow_a_bits_l k a bBits b l i acc1 | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_double_fw | val exp_double_fw
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(l: pos)
: t | val exp_double_fw
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(l: pos)
: t | let exp_double_fw (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits}) (l:pos) : t =
let acc0 = if bBits % l = 0 then one else exp_double_fw_acc0 k a1 bBits b1 a2 b2 l in
Loops.repeati (bBits / l) (exp_double_fw_f k a1 bBits b1 a2 b2 l) acc0 | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 72,
"end_line": 155,
"start_col": 0,
"start_line": 151
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit)
let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0
val exp_mont_ladder_swap_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap k a bBits b == exp_mont_ladder k a bBits b)
// a fixed window method
let exp_pow2 (#t:Type) (k:comm_monoid t) (a:t) (b:nat) : t =
Loops.repeat b (sqr k) a
val exp_pow2_lemma: #t:Type -> k:comm_monoid t -> a:t -> b:nat ->
Lemma (exp_pow2 k a b == pow k a (pow2 b))
let get_ith_lbits (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (l:pos) =
b / pow2 i % pow2 l
let get_bits_l (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) : r:nat{r < pow2 l} =
Math.Lemmas.lemma_mult_le_left l (i + 1) (bBits / l);
assert (l * (i + 1) <= l * (bBits / l));
get_ith_lbits bBits b (bBits - bBits % l - l * i - l) l
let mul_acc_pow_a_bits_l (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let bits_l = get_bits_l bBits b l i in
mul acc (pow k a bits_l)
let exp_fw_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let acc1 = exp_pow2 k acc l in
mul_acc_pow_a_bits_l k a bBits b l i acc1
let exp_fw_acc0 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos{bBits % l <> 0}) : t =
let bits_c = get_ith_lbits bBits b (bBits / l * l) l in
pow k a bits_c
let exp_fw (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) : t =
let acc0 = if bBits % l = 0 then one else exp_fw_acc0 k a bBits b l in
let res = Loops.repeati (bBits / l) (exp_fw_f k a bBits b l) acc0 in
res
val exp_fw_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos ->
Lemma (exp_fw k a bBits b l == pow k a b)
/// Multi-Exponentiation
// Double exponentiation [a1^b1 `mul` a2^b2]
//-------------------------------------------
let exp_double_fw_f (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits})
(l:pos) (i:nat{i < bBits / l}) (acc:t) : t
=
let acc1 = exp_fw_f k a2 bBits b2 l i acc in
mul_acc_pow_a_bits_l k a1 bBits b1 l i acc1
let exp_double_fw_acc0 (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits}) (l:pos{bBits % l <> 0}) : t =
let acc_a1 = exp_fw_acc0 k a1 bBits b1 l in
let acc_a2 = exp_fw_acc0 k a2 bBits b2 l in
mul acc_a1 acc_a2 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 20,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a1: t ->
bBits: Prims.nat ->
b1: Prims.nat{b1 < Prims.pow2 bBits} ->
a2: t ->
b2: Prims.nat{b2 < Prims.pow2 bBits} ->
l: Prims.pos
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Lib.LoopCombinators.repeati",
"Prims.op_Division",
"Lib.Exponentiation.exp_double_fw_f",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Lib.Exponentiation.Definition.one",
"Prims.bool",
"Lib.Exponentiation.exp_double_fw_acc0"
] | [] | false | false | false | false | false | let exp_double_fw
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(l: pos)
: t =
| let acc0 = if bBits % l = 0 then one else exp_double_fw_acc0 k a1 bBits b1 a2 b2 l in
Loops.repeati (bBits / l) (exp_double_fw_f k a1 bBits b1 a2 b2 l) acc0 | false |
Hacl.Impl.Curve25519.Finv.fst | Hacl.Impl.Curve25519.Finv.fsquare_times | val fsquare_times:
#s:field_spec
-> o:felem s
-> i:felem s
-> tmp:felem_wide s
-> n:size_t{v n > 0}
-> Stack unit
(requires fun h0 ->
live h0 o /\ live h0 i /\ live h0 tmp /\
(disjoint o i \/ o == i) /\
disjoint o tmp /\
disjoint tmp i /\
fsquare_times_inv h0 i)
(ensures fun h0 _ h1 ->
modifies (loc o |+| loc tmp) h0 h1 /\
fsquare_times_inv h1 o /\
feval h1 o == S.pow (feval #s h0 i) (pow2 (v n))) | val fsquare_times:
#s:field_spec
-> o:felem s
-> i:felem s
-> tmp:felem_wide s
-> n:size_t{v n > 0}
-> Stack unit
(requires fun h0 ->
live h0 o /\ live h0 i /\ live h0 tmp /\
(disjoint o i \/ o == i) /\
disjoint o tmp /\
disjoint tmp i /\
fsquare_times_inv h0 i)
(ensures fun h0 _ h1 ->
modifies (loc o |+| loc tmp) h0 h1 /\
fsquare_times_inv h1 o /\
feval h1 o == S.pow (feval #s h0 i) (pow2 (v n))) | let fsquare_times #s o inp tmp n =
let h0 = ST.get() in
fsqr_s #s o inp tmp;
S.lemma_pow_one (feval h0 inp);
S.lemma_pow_add (feval h0 inp) 1 1;
assert_norm (pow2 1 = 2);
let inv (h:mem) (i:nat{i < v n}) =
modifies (loc o |+| loc tmp) h0 h /\
fsquare_times_inv #s h o /\
feval h o == S.pow (feval #s h0 inp) (pow2 (i + 1)) in
let h1 = ST.get () in
assert (inv h1 0);
Lib.Loops.for 0ul (n -! 1ul) inv
(fun i ->
let h2 = ST.get () in
fsqr_s #s o o tmp;
S.lemma_pow_add (feval #s h0 inp) (pow2 (v i + 1)) (pow2 (v i + 1));
Math.Lemmas.pow2_double_sum (v i + 1)) | {
"file_name": "code/curve25519/Hacl.Impl.Curve25519.Finv.fst",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 42,
"end_line": 120,
"start_col": 0,
"start_line": 100
} | module Hacl.Impl.Curve25519.Finv
open FStar.HyperStack
open FStar.HyperStack.All
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Impl.Curve25519.Fields
module ST = FStar.HyperStack.ST
module C = Hacl.Impl.Curve25519.Fields.Core
module S = Hacl.Spec.Curve25519.Finv
module P = Spec.Curve25519
let _: squash (inversion field_spec) = allow_inversion field_spec
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0 --record_options"
noextract
val fsquare_times_inv: #s:field_spec -> h:mem -> f:felem s -> Type0
let fsquare_times_inv #s h f =
match s with
| M51 -> C.f51_felem_fits h f (1, 2, 1, 1, 1)
| M64 -> True
val fsqr_s:
#s:field_spec
-> out:felem s
-> f1:felem s
-> tmp:felem_wide s
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h tmp /\
(disjoint out f1 \/ out == f1) /\
(disjoint out tmp) /\
disjoint tmp f1 /\
fsquare_times_inv h f1)
(ensures fun h0 _ h1 ->
modifies (loc out |+| loc tmp) h0 h1 /\
fsquare_times_inv h1 out /\
feval h1 out == P.fmul (feval h0 f1) (feval h0 f1))
[@ Meta.Attribute.inline_ ]
let fsqr_s #s out f1 tmp =
C.fsqr #s out f1 tmp
noextract
val fmuls_pre: #s:field_spec -> h:mem -> f1:felem s -> f2:felem s -> Type0
let fmuls_pre #s h f1 f2 =
match s with
| M51 -> f51_felem_fits h f1 (1, 2, 1, 1, 1) /\ f51_felem_fits h f2 (1, 2, 1, 1, 1)
| M64 -> True
val fmul_s:
#s:field_spec
-> out:felem s
-> f1:felem s
-> f2:felem s
-> tmp:felem_wide2 s
-> Stack unit
(requires fun h ->
live h out /\ live h f1 /\ live h f2 /\ live h tmp /\
(disjoint out f1 \/ out == f1) /\
(disjoint out f2 \/ out == f2) /\
(disjoint out tmp) /\
(disjoint f1 f2 \/ f1 == f2) /\
disjoint f1 tmp /\
disjoint f2 tmp /\
fmuls_pre h f1 f2)
(ensures fun h0 _ h1 ->
modifies (loc out |+| loc tmp) h0 h1 /\ fsquare_times_inv h1 out /\
feval h1 out == P.fmul (feval h0 f1) (feval h0 f2))
[@ Meta.Attribute.inline_ ]
let fmul_s #s out f1 f2 tmp =
C.fmul #s out f1 f2 tmp
val fsquare_times:
#s:field_spec
-> o:felem s
-> i:felem s
-> tmp:felem_wide s
-> n:size_t{v n > 0}
-> Stack unit
(requires fun h0 ->
live h0 o /\ live h0 i /\ live h0 tmp /\
(disjoint o i \/ o == i) /\
disjoint o tmp /\
disjoint tmp i /\
fsquare_times_inv h0 i)
(ensures fun h0 _ h1 ->
modifies (loc o |+| loc tmp) h0 h1 /\
fsquare_times_inv h1 o /\
feval h1 o == S.pow (feval #s h0 i) (pow2 (v n))) | {
"checked_file": "/",
"dependencies": [
"Spec.Curve25519.fst.checked",
"prims.fst.checked",
"Meta.Attribute.fst.checked",
"Lib.Loops.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Curve25519.Finv.fst.checked",
"Hacl.Impl.Curve25519.Fields.Core.fsti.checked",
"Hacl.Impl.Curve25519.Fields.fst.checked",
"FStar.UInt32.fsti.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.Curve25519.Finv.fst"
} | [
{
"abbrev": true,
"full_module": "Spec.Curve25519",
"short_module": "P"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Curve25519.Finv",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Impl.Curve25519.Fields.Core",
"short_module": "C"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519.Fields",
"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": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Impl.Curve25519",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": 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 |
o: Hacl.Impl.Curve25519.Fields.Core.felem s ->
i: Hacl.Impl.Curve25519.Fields.Core.felem s ->
tmp: Hacl.Impl.Curve25519.Fields.Core.felem_wide s ->
n: Lib.IntTypes.size_t{Lib.IntTypes.v n > 0}
-> FStar.HyperStack.ST.Stack Prims.unit | FStar.HyperStack.ST.Stack | [] | [] | [
"Hacl.Impl.Curve25519.Fields.Core.field_spec",
"Hacl.Impl.Curve25519.Fields.Core.felem",
"Hacl.Impl.Curve25519.Fields.Core.felem_wide",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_GreaterThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Loops.for",
"FStar.UInt32.__uint_to_t",
"Lib.IntTypes.op_Subtraction_Bang",
"Prims.l_and",
"Prims.op_LessThanOrEqual",
"Prims.op_LessThan",
"FStar.Math.Lemmas.pow2_double_sum",
"Prims.op_Addition",
"Prims.unit",
"Hacl.Spec.Curve25519.Finv.lemma_pow_add",
"Hacl.Impl.Curve25519.Fields.Core.feval",
"Prims.pow2",
"Hacl.Impl.Curve25519.Finv.fsqr_s",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"Prims._assert",
"Prims.nat",
"Prims.logical",
"Lib.Buffer.modifies",
"Lib.Buffer.op_Bar_Plus_Bar",
"Lib.Buffer.loc",
"Lib.Buffer.MUT",
"Hacl.Impl.Curve25519.Fields.Core.limb",
"Hacl.Impl.Curve25519.Fields.Core.wide",
"Hacl.Impl.Curve25519.Finv.fsquare_times_inv",
"Prims.eq2",
"Spec.Curve25519.elem",
"Hacl.Spec.Curve25519.Finv.pow",
"FStar.Pervasives.assert_norm",
"Prims.op_Equality",
"Prims.int",
"Hacl.Spec.Curve25519.Finv.lemma_pow_one"
] | [] | false | true | false | false | false | let fsquare_times #s o inp tmp n =
| let h0 = ST.get () in
fsqr_s #s o inp tmp;
S.lemma_pow_one (feval h0 inp);
S.lemma_pow_add (feval h0 inp) 1 1;
assert_norm (pow2 1 = 2);
let inv (h: mem) (i: nat{i < v n}) =
modifies (loc o |+| loc tmp) h0 h /\ fsquare_times_inv #s h o /\
feval h o == S.pow (feval #s h0 inp) (pow2 (i + 1))
in
let h1 = ST.get () in
assert (inv h1 0);
Lib.Loops.for 0ul
(n -! 1ul)
inv
(fun i ->
let h2 = ST.get () in
fsqr_s #s o o tmp;
S.lemma_pow_add (feval #s h0 inp) (pow2 (v i + 1)) (pow2 (v i + 1));
Math.Lemmas.pow2_double_sum (v i + 1)) | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_four_fw_f | val exp_four_fw_f
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(a3: t)
(b3: nat{b3 < pow2 bBits})
(a4: t)
(b4: nat{b4 < pow2 bBits})
(l: pos)
(i: nat{i < bBits / l})
(acc: t)
: t | val exp_four_fw_f
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(a3: t)
(b3: nat{b3 < pow2 bBits})
(a4: t)
(b4: nat{b4 < pow2 bBits})
(l: pos)
(i: nat{i < bBits / l})
(acc: t)
: t | let exp_four_fw_f (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits})
(a3:t) (b3:nat{b3 < pow2 bBits})
(a4:t) (b4:nat{b4 < pow2 bBits})
(l:pos) (i:nat{i < bBits / l}) (acc:t) : t
=
let acc = exp_fw_f k a4 bBits b4 l i acc in
let acc = mul_acc_pow_a_bits_l k a3 bBits b3 l i acc in
let acc = mul_acc_pow_a_bits_l k a2 bBits b2 l i acc in
let acc = mul_acc_pow_a_bits_l k a1 bBits b1 l i acc in
acc | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 5,
"end_line": 178,
"start_col": 0,
"start_line": 167
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit)
let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0
val exp_mont_ladder_swap_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap k a bBits b == exp_mont_ladder k a bBits b)
// a fixed window method
let exp_pow2 (#t:Type) (k:comm_monoid t) (a:t) (b:nat) : t =
Loops.repeat b (sqr k) a
val exp_pow2_lemma: #t:Type -> k:comm_monoid t -> a:t -> b:nat ->
Lemma (exp_pow2 k a b == pow k a (pow2 b))
let get_ith_lbits (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (l:pos) =
b / pow2 i % pow2 l
let get_bits_l (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) : r:nat{r < pow2 l} =
Math.Lemmas.lemma_mult_le_left l (i + 1) (bBits / l);
assert (l * (i + 1) <= l * (bBits / l));
get_ith_lbits bBits b (bBits - bBits % l - l * i - l) l
let mul_acc_pow_a_bits_l (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let bits_l = get_bits_l bBits b l i in
mul acc (pow k a bits_l)
let exp_fw_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let acc1 = exp_pow2 k acc l in
mul_acc_pow_a_bits_l k a bBits b l i acc1
let exp_fw_acc0 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos{bBits % l <> 0}) : t =
let bits_c = get_ith_lbits bBits b (bBits / l * l) l in
pow k a bits_c
let exp_fw (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) : t =
let acc0 = if bBits % l = 0 then one else exp_fw_acc0 k a bBits b l in
let res = Loops.repeati (bBits / l) (exp_fw_f k a bBits b l) acc0 in
res
val exp_fw_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos ->
Lemma (exp_fw k a bBits b l == pow k a b)
/// Multi-Exponentiation
// Double exponentiation [a1^b1 `mul` a2^b2]
//-------------------------------------------
let exp_double_fw_f (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits})
(l:pos) (i:nat{i < bBits / l}) (acc:t) : t
=
let acc1 = exp_fw_f k a2 bBits b2 l i acc in
mul_acc_pow_a_bits_l k a1 bBits b1 l i acc1
let exp_double_fw_acc0 (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits}) (l:pos{bBits % l <> 0}) : t =
let acc_a1 = exp_fw_acc0 k a1 bBits b1 l in
let acc_a2 = exp_fw_acc0 k a2 bBits b2 l in
mul acc_a1 acc_a2
#push-options "--z3rlimit 20"
let exp_double_fw (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits}) (l:pos) : t =
let acc0 = if bBits % l = 0 then one else exp_double_fw_acc0 k a1 bBits b1 a2 b2 l in
Loops.repeati (bBits / l) (exp_double_fw_f k a1 bBits b1 a2 b2 l) acc0
#pop-options
val exp_double_fw_lemma: #t:Type -> k:comm_monoid t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits} -> l:pos ->
Lemma (exp_double_fw k a1 bBits b1 a2 b2 l == mul (pow k a1 b1) (pow k a2 b2))
// [a1^b1 `mul` a2^b2 `mul` a3^b3 `mul` a4^b4]
//---------------------------------------------- | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a1: t ->
bBits: Prims.nat ->
b1: Prims.nat{b1 < Prims.pow2 bBits} ->
a2: t ->
b2: Prims.nat{b2 < Prims.pow2 bBits} ->
a3: t ->
b3: Prims.nat{b3 < Prims.pow2 bBits} ->
a4: t ->
b4: Prims.nat{b4 < Prims.pow2 bBits} ->
l: Prims.pos ->
i: Prims.nat{i < bBits / l} ->
acc: t
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Prims.op_Division",
"Lib.Exponentiation.mul_acc_pow_a_bits_l",
"Lib.Exponentiation.exp_fw_f"
] | [] | false | false | false | false | false | let exp_four_fw_f
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(a3: t)
(b3: nat{b3 < pow2 bBits})
(a4: t)
(b4: nat{b4 < pow2 bBits})
(l: pos)
(i: nat{i < bBits / l})
(acc: t)
: t =
| let acc = exp_fw_f k a4 bBits b4 l i acc in
let acc = mul_acc_pow_a_bits_l k a3 bBits b3 l i acc in
let acc = mul_acc_pow_a_bits_l k a2 bBits b2 l i acc in
let acc = mul_acc_pow_a_bits_l k a1 bBits b1 l i acc in
acc | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_four_fw | val exp_four_fw
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(a3: t)
(b3: nat{b3 < pow2 bBits})
(a4: t)
(b4: nat{b4 < pow2 bBits})
(l: pos)
: t | val exp_four_fw
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(a3: t)
(b3: nat{b3 < pow2 bBits})
(a4: t)
(b4: nat{b4 < pow2 bBits})
(l: pos)
: t | let exp_four_fw (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits})
(a3:t) (b3:nat{b3 < pow2 bBits})
(a4:t) (b4:nat{b4 < pow2 bBits})
(l:pos) : t =
let acc0 =
if bBits % l = 0 then one
else exp_four_fw_acc0 k a1 bBits b1 a2 b2 a3 b3 a4 b4 l in
Loops.repeati (bBits / l)
(exp_four_fw_f k a1 bBits b1 a2 b2 a3 b3 a4 b4 l) acc0 | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 58,
"end_line": 200,
"start_col": 0,
"start_line": 190
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit)
let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0
val exp_mont_ladder_swap_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap k a bBits b == exp_mont_ladder k a bBits b)
// a fixed window method
let exp_pow2 (#t:Type) (k:comm_monoid t) (a:t) (b:nat) : t =
Loops.repeat b (sqr k) a
val exp_pow2_lemma: #t:Type -> k:comm_monoid t -> a:t -> b:nat ->
Lemma (exp_pow2 k a b == pow k a (pow2 b))
let get_ith_lbits (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (l:pos) =
b / pow2 i % pow2 l
let get_bits_l (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) : r:nat{r < pow2 l} =
Math.Lemmas.lemma_mult_le_left l (i + 1) (bBits / l);
assert (l * (i + 1) <= l * (bBits / l));
get_ith_lbits bBits b (bBits - bBits % l - l * i - l) l
let mul_acc_pow_a_bits_l (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let bits_l = get_bits_l bBits b l i in
mul acc (pow k a bits_l)
let exp_fw_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let acc1 = exp_pow2 k acc l in
mul_acc_pow_a_bits_l k a bBits b l i acc1
let exp_fw_acc0 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos{bBits % l <> 0}) : t =
let bits_c = get_ith_lbits bBits b (bBits / l * l) l in
pow k a bits_c
let exp_fw (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) : t =
let acc0 = if bBits % l = 0 then one else exp_fw_acc0 k a bBits b l in
let res = Loops.repeati (bBits / l) (exp_fw_f k a bBits b l) acc0 in
res
val exp_fw_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos ->
Lemma (exp_fw k a bBits b l == pow k a b)
/// Multi-Exponentiation
// Double exponentiation [a1^b1 `mul` a2^b2]
//-------------------------------------------
let exp_double_fw_f (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits})
(l:pos) (i:nat{i < bBits / l}) (acc:t) : t
=
let acc1 = exp_fw_f k a2 bBits b2 l i acc in
mul_acc_pow_a_bits_l k a1 bBits b1 l i acc1
let exp_double_fw_acc0 (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits}) (l:pos{bBits % l <> 0}) : t =
let acc_a1 = exp_fw_acc0 k a1 bBits b1 l in
let acc_a2 = exp_fw_acc0 k a2 bBits b2 l in
mul acc_a1 acc_a2
#push-options "--z3rlimit 20"
let exp_double_fw (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits}) (l:pos) : t =
let acc0 = if bBits % l = 0 then one else exp_double_fw_acc0 k a1 bBits b1 a2 b2 l in
Loops.repeati (bBits / l) (exp_double_fw_f k a1 bBits b1 a2 b2 l) acc0
#pop-options
val exp_double_fw_lemma: #t:Type -> k:comm_monoid t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits} -> l:pos ->
Lemma (exp_double_fw k a1 bBits b1 a2 b2 l == mul (pow k a1 b1) (pow k a2 b2))
// [a1^b1 `mul` a2^b2 `mul` a3^b3 `mul` a4^b4]
//----------------------------------------------
let exp_four_fw_f (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits})
(a3:t) (b3:nat{b3 < pow2 bBits})
(a4:t) (b4:nat{b4 < pow2 bBits})
(l:pos) (i:nat{i < bBits / l}) (acc:t) : t
=
let acc = exp_fw_f k a4 bBits b4 l i acc in
let acc = mul_acc_pow_a_bits_l k a3 bBits b3 l i acc in
let acc = mul_acc_pow_a_bits_l k a2 bBits b2 l i acc in
let acc = mul_acc_pow_a_bits_l k a1 bBits b1 l i acc in
acc
let exp_four_fw_acc0 (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits})
(a3:t) (b3:nat{b3 < pow2 bBits})
(a4:t) (b4:nat{b4 < pow2 bBits})
(l:pos{bBits % l <> 0}) : t =
let acc_a12 = exp_double_fw_acc0 k a1 bBits b1 a2 b2 l in
let acc_a34 = exp_double_fw_acc0 k a3 bBits b3 a4 b4 l in
mul acc_a12 acc_a34 | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a1: t ->
bBits: Prims.nat ->
b1: Prims.nat{b1 < Prims.pow2 bBits} ->
a2: t ->
b2: Prims.nat{b2 < Prims.pow2 bBits} ->
a3: t ->
b3: Prims.nat{b3 < Prims.pow2 bBits} ->
a4: t ->
b4: Prims.nat{b4 < Prims.pow2 bBits} ->
l: Prims.pos
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Lib.LoopCombinators.repeati",
"Prims.op_Division",
"Lib.Exponentiation.exp_four_fw_f",
"Prims.op_Equality",
"Prims.int",
"Prims.op_Modulus",
"Lib.Exponentiation.Definition.one",
"Prims.bool",
"Lib.Exponentiation.exp_four_fw_acc0"
] | [] | false | false | false | false | false | let exp_four_fw
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(a3: t)
(b3: nat{b3 < pow2 bBits})
(a4: t)
(b4: nat{b4 < pow2 bBits})
(l: pos)
: t =
| let acc0 = if bBits % l = 0 then one else exp_four_fw_acc0 k a1 bBits b1 a2 b2 a3 b3 a4 b4 l in
Loops.repeati (bBits / l) (exp_four_fw_f k a1 bBits b1 a2 b2 a3 b3 a4 b4 l) acc0 | false |
Lib.Exponentiation.fsti | Lib.Exponentiation.exp_four_fw_acc0 | val exp_four_fw_acc0
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(a3: t)
(b3: nat{b3 < pow2 bBits})
(a4: t)
(b4: nat{b4 < pow2 bBits})
(l: pos{bBits % l <> 0})
: t | val exp_four_fw_acc0
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(a3: t)
(b3: nat{b3 < pow2 bBits})
(a4: t)
(b4: nat{b4 < pow2 bBits})
(l: pos{bBits % l <> 0})
: t | let exp_four_fw_acc0 (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits})
(a3:t) (b3:nat{b3 < pow2 bBits})
(a4:t) (b4:nat{b4 < pow2 bBits})
(l:pos{bBits % l <> 0}) : t =
let acc_a12 = exp_double_fw_acc0 k a1 bBits b1 a2 b2 l in
let acc_a34 = exp_double_fw_acc0 k a3 bBits b3 a4 b4 l in
mul acc_a12 acc_a34 | {
"file_name": "lib/Lib.Exponentiation.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 21,
"end_line": 188,
"start_col": 0,
"start_line": 180
} | module Lib.Exponentiation
open FStar.Mul
module Loops = Lib.LoopCombinators
include Lib.Exponentiation.Definition
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let get_ith_bit (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) =
b / pow2 i % 2
//a right-to-left binary method
let exp_rl_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((acc, c) : tuple2 t t) : tuple2 t t =
let acc = if (get_ith_bit bBits b i = 0) then acc else mul acc c in
let c = mul c c in
(acc, c)
let exp_rl (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (acc, c) = Loops.repeati bBits (exp_rl_f k bBits b) (one, a) in
acc
val exp_rl_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_rl k a bBits b == pow k a b)
//a left-to-right binary method
let exp_lr_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (acc:t) : t =
let acc = mul acc acc in
let acc = if (get_ith_bit bBits b (bBits - 1 - i) = 0) then acc else mul acc a in
acc
let exp_lr (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
Loops.repeati bBits (exp_lr_f k a bBits b) one
val exp_lr_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_lr k a bBits b == pow k a b)
// Montgomery ladder for exponentiation
let exp_mont_ladder_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
if (get_ith_bit bBits b (bBits - 1 - i) = 0) then
(mul r0 r0, mul r1 r0)
else
(mul r0 r1, mul r1 r1)
let exp_mont_ladder (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_f k bBits b) (one, a) in
r0
val exp_mont_ladder_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder k a bBits b == pow k a b)
// Montgomery ladder for exponentiation with cswap
let cswap (#t:Type) (sw:nat) (r0:t) (r1:t) : tuple2 t t =
if sw = 1 then (r1, r0) else (r0, r1)
// cswap -> step -> cswap -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap2_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1) : tuple2 t t) : tuple2 t t =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let r0, r1 = cswap bit r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
let r0, r1 = cswap bit r0 r1 in
(r0, r1)
let exp_mont_ladder_swap2 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1) = Loops.repeati bBits (exp_mont_ladder_swap2_f k bBits b) (one, a) in
r0
val exp_mont_ladder_swap2_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap2 k a bBits b == exp_mont_ladder k a bBits b)
// cswap -> step -> cswap -> step -> cswap -> ..
let exp_mont_ladder_swap_f (#t:Type) (k:comm_monoid t) (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) ((r0, r1, privbit) : tuple3 t t nat) : tuple3 t t nat =
let bit = get_ith_bit bBits b (bBits - 1 - i) in
let sw = (bit + privbit) % 2 in
let r0, r1 = cswap sw r0 r1 in
let r0, r1 = (mul r0 r0, mul r1 r0) in
(r0, r1, bit)
let exp_mont_ladder_swap (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) : t =
let (r0, r1, sw) = Loops.repeati bBits (exp_mont_ladder_swap_f k bBits b) (one, a, 0) in
let (r0, r1) = cswap sw r0 r1 in
r0
val exp_mont_ladder_swap_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} ->
Lemma (exp_mont_ladder_swap k a bBits b == exp_mont_ladder k a bBits b)
// a fixed window method
let exp_pow2 (#t:Type) (k:comm_monoid t) (a:t) (b:nat) : t =
Loops.repeat b (sqr k) a
val exp_pow2_lemma: #t:Type -> k:comm_monoid t -> a:t -> b:nat ->
Lemma (exp_pow2 k a b == pow k a (pow2 b))
let get_ith_lbits (bBits:nat) (b:nat{b < pow2 bBits}) (i:nat{i < bBits}) (l:pos) =
b / pow2 i % pow2 l
let get_bits_l (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) : r:nat{r < pow2 l} =
Math.Lemmas.lemma_mult_le_left l (i + 1) (bBits / l);
assert (l * (i + 1) <= l * (bBits / l));
get_ith_lbits bBits b (bBits - bBits % l - l * i - l) l
let mul_acc_pow_a_bits_l (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let bits_l = get_bits_l bBits b l i in
mul acc (pow k a bits_l)
let exp_fw_f (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) (i:nat{i < bBits / l}) (acc:t) : t =
let acc1 = exp_pow2 k acc l in
mul_acc_pow_a_bits_l k a bBits b l i acc1
let exp_fw_acc0 (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos{bBits % l <> 0}) : t =
let bits_c = get_ith_lbits bBits b (bBits / l * l) l in
pow k a bits_c
let exp_fw (#t:Type) (k:comm_monoid t) (a:t) (bBits:nat) (b:nat{b < pow2 bBits}) (l:pos) : t =
let acc0 = if bBits % l = 0 then one else exp_fw_acc0 k a bBits b l in
let res = Loops.repeati (bBits / l) (exp_fw_f k a bBits b l) acc0 in
res
val exp_fw_lemma: #t:Type -> k:comm_monoid t -> a:t -> bBits:nat -> b:nat{b < pow2 bBits} -> l:pos ->
Lemma (exp_fw k a bBits b l == pow k a b)
/// Multi-Exponentiation
// Double exponentiation [a1^b1 `mul` a2^b2]
//-------------------------------------------
let exp_double_fw_f (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits})
(l:pos) (i:nat{i < bBits / l}) (acc:t) : t
=
let acc1 = exp_fw_f k a2 bBits b2 l i acc in
mul_acc_pow_a_bits_l k a1 bBits b1 l i acc1
let exp_double_fw_acc0 (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits}) (l:pos{bBits % l <> 0}) : t =
let acc_a1 = exp_fw_acc0 k a1 bBits b1 l in
let acc_a2 = exp_fw_acc0 k a2 bBits b2 l in
mul acc_a1 acc_a2
#push-options "--z3rlimit 20"
let exp_double_fw (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits}) (l:pos) : t =
let acc0 = if bBits % l = 0 then one else exp_double_fw_acc0 k a1 bBits b1 a2 b2 l in
Loops.repeati (bBits / l) (exp_double_fw_f k a1 bBits b1 a2 b2 l) acc0
#pop-options
val exp_double_fw_lemma: #t:Type -> k:comm_monoid t
-> a1:t -> bBits:nat -> b1:nat{b1 < pow2 bBits}
-> a2:t -> b2:nat{b2 < pow2 bBits} -> l:pos ->
Lemma (exp_double_fw k a1 bBits b1 a2 b2 l == mul (pow k a1 b1) (pow k a2 b2))
// [a1^b1 `mul` a2^b2 `mul` a3^b3 `mul` a4^b4]
//----------------------------------------------
let exp_four_fw_f (#t:Type) (k:comm_monoid t)
(a1:t) (bBits:nat) (b1:nat{b1 < pow2 bBits})
(a2:t) (b2:nat{b2 < pow2 bBits})
(a3:t) (b3:nat{b3 < pow2 bBits})
(a4:t) (b4:nat{b4 < pow2 bBits})
(l:pos) (i:nat{i < bBits / l}) (acc:t) : t
=
let acc = exp_fw_f k a4 bBits b4 l i acc in
let acc = mul_acc_pow_a_bits_l k a3 bBits b3 l i acc in
let acc = mul_acc_pow_a_bits_l k a2 bBits b2 l i acc in
let acc = mul_acc_pow_a_bits_l k a1 bBits b1 l i acc in
acc | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"Lib.LoopCombinators.fsti.checked",
"Lib.Exponentiation.Definition.fsti.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked"
],
"interface_file": false,
"source_file": "Lib.Exponentiation.fsti"
} | [
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib.Exponentiation.Definition",
"short_module": null
},
{
"abbrev": true,
"full_module": "Lib.LoopCombinators",
"short_module": "Loops"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "Lib",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
k: Lib.Exponentiation.Definition.comm_monoid t ->
a1: t ->
bBits: Prims.nat ->
b1: Prims.nat{b1 < Prims.pow2 bBits} ->
a2: t ->
b2: Prims.nat{b2 < Prims.pow2 bBits} ->
a3: t ->
b3: Prims.nat{b3 < Prims.pow2 bBits} ->
a4: t ->
b4: Prims.nat{b4 < Prims.pow2 bBits} ->
l: Prims.pos{bBits % l <> 0}
-> t | Prims.Tot | [
"total"
] | [] | [
"Lib.Exponentiation.Definition.comm_monoid",
"Prims.nat",
"Prims.b2t",
"Prims.op_LessThan",
"Prims.pow2",
"Prims.pos",
"Prims.op_disEquality",
"Prims.int",
"Prims.op_Modulus",
"Lib.Exponentiation.Definition.mul",
"Lib.Exponentiation.exp_double_fw_acc0"
] | [] | false | false | false | false | false | let exp_four_fw_acc0
(#t: Type)
(k: comm_monoid t)
(a1: t)
(bBits: nat)
(b1: nat{b1 < pow2 bBits})
(a2: t)
(b2: nat{b2 < pow2 bBits})
(a3: t)
(b3: nat{b3 < pow2 bBits})
(a4: t)
(b4: nat{b4 < pow2 bBits})
(l: pos{bBits % l <> 0})
: t =
| let acc_a12 = exp_double_fw_acc0 k a1 bBits b1 a2 b2 l in
let acc_a34 = exp_double_fw_acc0 k a3 bBits b3 a4 b4 l in
mul acc_a12 acc_a34 | false |
Vale.Poly1305.Bitvectors.fsti | Vale.Poly1305.Bitvectors.lowerUpper128u | val lowerUpper128u (l u: uint_t 64) : uint_t 128 | val lowerUpper128u (l u: uint_t 64) : uint_t 128 | let lowerUpper128u (l:uint_t 64) (u:uint_t 64) : uint_t 128 =
0x10000000000000000 * u + l | {
"file_name": "vale/code/crypto/poly1305/x64/Vale.Poly1305.Bitvectors.fsti",
"git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872",
"git_url": "https://github.com/project-everest/hacl-star.git",
"project_name": "hacl-star"
} | {
"end_col": 31,
"end_line": 57,
"start_col": 0,
"start_line": 56
} | module Vale.Poly1305.Bitvectors
open FStar.BV
open FStar.Mul
open FStar.UInt
val lemma_shr2: (x:uint_t 64) -> Lemma
((shift_right #64 x 2 == udiv #64 x 4))
[SMTPat (shift_right #64 x 2)]
val lemma_shr4: x:uint_t 64 -> Lemma (shift_right #64 x 4 == udiv #64 x 16)
[SMTPat (shift_right #64 x 4)]
val lemma_and_mod_n: x:uint_t 64 -> Lemma (logand #64 x 3 == mod #64 x 4 /\
logand #64 x 15 == mod #64 x 16)
[SMTPat (logand #64 x 3);
SMTPat (logand #64 x 15)]
val lemma_clear_lower_2: x:uint_t 64 ->
Lemma (logand #64 x 0xfffffffffffffffc == mul_mod #64 (udiv #64 x 4) 4)
[SMTPat (logand #64 x 0xfffffffffffffffc)]
val lemma_and_constants: x:uint_t 64 ->
Lemma (logand #64 x 0 == 0 /\ logand #64 x 0xffffffffffffffff == x)
[SMTPat (logand #64 x 0); SMTPat (logand #64 x 0xffffffffffffffff)]
val lemma_poly_constants: x:uint_t 64 ->
Lemma (logand #64 x 0x0ffffffc0fffffff < 0x1000000000000000 /\
logand #64 x 0x0ffffffc0ffffffc < 0x1000000000000000 /\
mod #64 (logand #64 x 0x0ffffffc0ffffffc) 4 == 0)
[SMTPat (logand #64 x 0x0ffffffc0fffffff);
SMTPat (logand #64 x 0x0ffffffc0ffffffc);
SMTPat (logand #64 x 0x0ffffffc0ffffffc)]
val lemma_and_commutes: x:uint_t 64 -> y:uint_t 64 ->
Lemma (logand #64 x y == logand #64 y x)
val lemma_bv128_64_64_and_helper: x:bv_t 128 -> x0:bv_t 64 -> x1:bv_t 64 ->
y:bv_t 128 -> y0:bv_t 64 -> y1:bv_t 64 ->
z:bv_t 128 -> z0:bv_t 64 -> z1:bv_t 64 ->
Lemma (requires (z0 == bvand #64 x0 y0 /\
z1 == bvand #64 x1 y1 /\
x == bvor #128 (bvshl #128 (bv_uext #64 #64 x1) 64)
(bv_uext #64 #64 x0) /\
y == bvor #128 (bvshl #128 (bv_uext #64 #64 y1) 64)
(bv_uext #64 #64 y0) /\
z == bvor #128 (bvshl #128 (bv_uext #64 #64 z1) 64)
(bv_uext #64 #64 z0)))
(ensures (z == bvand #128 x y))
val bv128_64_64: x1:bv_t 64 -> x0:bv_t 64 -> Tot (bv_t 128)
val lemma_bv128_64_64_and: x:bv_t 128 -> x0:bv_t 64 -> x1:bv_t 64 ->
y:bv_t 128 -> y0:bv_t 64 -> y1:bv_t 64 ->
z:bv_t 128 -> z0:bv_t 64 -> z1:bv_t 64 ->
Lemma (requires (z0 == bvand #64 x0 y0 /\
z1 == bvand #64 x1 y1 /\
x == bv128_64_64 x0 x1 /\
y == bv128_64_64 y0 y1 /\
z == bv128_64_64 z0 z1))
(ensures (z == bvand #128 x y)) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"FStar.UInt.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.BV.fsti.checked"
],
"interface_file": false,
"source_file": "Vale.Poly1305.Bitvectors.fsti"
} | [
{
"abbrev": false,
"full_module": "Vale.Math.Bits",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Bv_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Lib.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Math.Lemmas",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Derived",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.UInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.BV",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Poly1305",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.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": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | l: FStar.UInt.uint_t 64 -> u33: FStar.UInt.uint_t 64 -> FStar.UInt.uint_t 128 | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt.uint_t",
"Prims.op_Addition",
"FStar.Mul.op_Star"
] | [] | false | false | false | false | false | let lowerUpper128u (l u: uint_t 64) : uint_t 128 =
| 0x10000000000000000 * u + l | false |
LowParse.SLow.BoundedInt.fsti | LowParse.SLow.BoundedInt.serialize32_bounded_integer | val serialize32_bounded_integer (sz: integer_size)
: Tot (serializer32 (serialize_bounded_integer sz)) | val serialize32_bounded_integer (sz: integer_size)
: Tot (serializer32 (serialize_bounded_integer sz)) | let serialize32_bounded_integer
(sz: integer_size)
: Tot (serializer32 (serialize_bounded_integer sz))
= match sz with
| 1 -> serialize32_bounded_integer_1
| 2 -> serialize32_bounded_integer_2
| 3 -> serialize32_bounded_integer_3
| 4 -> serialize32_bounded_integer_4 | {
"file_name": "src/lowparse/LowParse.SLow.BoundedInt.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 38,
"end_line": 57,
"start_col": 0,
"start_line": 50
} | module LowParse.SLow.BoundedInt
include LowParse.Spec.BoundedInt
include LowParse.SLow.Base
(* bounded integers *)
inline_for_extraction
val parse32_bounded_integer_1
: (parser32 (parse_bounded_integer 1))
inline_for_extraction
val parse32_bounded_integer_2
: (parser32 (parse_bounded_integer 2))
inline_for_extraction
val parse32_bounded_integer_3
: (parser32 (parse_bounded_integer 3))
inline_for_extraction
val parse32_bounded_integer_4
: (parser32 (parse_bounded_integer 4))
inline_for_extraction
noextract
let parse32_bounded_integer (sz: integer_size) : Tot (parser32 (parse_bounded_integer sz))
= match sz with
| 1 -> parse32_bounded_integer_1
| 2 -> parse32_bounded_integer_2
| 3 -> parse32_bounded_integer_3
| 4 -> parse32_bounded_integer_4
inline_for_extraction
val serialize32_bounded_integer_1
: (serializer32 (serialize_bounded_integer 1))
inline_for_extraction
val serialize32_bounded_integer_2
: (serializer32 (serialize_bounded_integer 2))
inline_for_extraction
val serialize32_bounded_integer_3
: (serializer32 (serialize_bounded_integer 3))
inline_for_extraction
val serialize32_bounded_integer_4
: (serializer32 (serialize_bounded_integer 4))
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.SLow.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.BoundedInt.fsti"
} | [
{
"abbrev": false,
"full_module": "LowParse.SLow.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | sz: LowParse.Spec.BoundedInt.integer_size
-> LowParse.SLow.Base.serializer32 (LowParse.Spec.BoundedInt.serialize_bounded_integer sz) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.SLow.BoundedInt.serialize32_bounded_integer_1",
"LowParse.SLow.BoundedInt.serialize32_bounded_integer_2",
"LowParse.SLow.BoundedInt.serialize32_bounded_integer_3",
"LowParse.SLow.BoundedInt.serialize32_bounded_integer_4",
"LowParse.SLow.Base.serializer32",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.BoundedInt.parse_bounded_integer",
"LowParse.Spec.BoundedInt.serialize_bounded_integer"
] | [] | false | false | false | false | false | let serialize32_bounded_integer (sz: integer_size)
: Tot (serializer32 (serialize_bounded_integer sz)) =
| match sz with
| 1 -> serialize32_bounded_integer_1
| 2 -> serialize32_bounded_integer_2
| 3 -> serialize32_bounded_integer_3
| 4 -> serialize32_bounded_integer_4 | false |
Steel.ST.Printf.fst | Steel.ST.Printf.test_printf | val test_printf
(m: UInt64.t)
(l: UInt32.t)
(x: A.array bool {A.length x == U32.v l})
(v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v) | val test_printf
(m: UInt64.t)
(l: UInt32.t)
(x: A.array bool {A.length x == U32.v l})
(v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v) | let test_printf (m:UInt64.t) (l:UInt32.t) (x:A.array bool {A.length x == U32.v l}) (v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v)
= printf "Hello %b Steel.ST %uL Printf %xb %s"
true //%b boolean
m //%uL u64
l x //%xb (buffer bool)
"bye"
done | {
"file_name": "lib/steel/Steel.ST.Printf.fst",
"git_rev": "f984200f79bdc452374ae994a5ca837496476c41",
"git_url": "https://github.com/FStarLang/steel.git",
"project_name": "steel"
} | {
"end_col": 18,
"end_line": 566,
"start_col": 0,
"start_line": 559
} | (*
Copyright 2008-2022 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module Steel.ST.Printf
/// This module provides Steel.ST imperative printing functions for several
/// primitive Low* types, including
/// -- booleans (%b)
/// -- characters (%c)
/// -- strings (%s)
/// -- machine integers
/// (UInt8.t as %uy, UInt16.t as %us, UInt32.t as %ul, and UInt64.t as %uL;
/// Int8.t as %y, Int16.t as %i, Int32.t as %l , and Int64.t as %L)
/// -- and arrays of these base types formatted
/// as %xN, where N is the format specifier for the array element type
/// e.g., %xuy for buffers of UInt8.t
/// The main function of this module is `printf`
/// There are a few main differences relative to C printf
/// -- The format specifiers are different (see above)
///
/// -- For technical reasons explained below, an extra dummy
/// argument `done` has to be provided at the end for the
/// computation to have any effect.
///
/// E.g., one must write
/// `printf "%b %c" true 'c' done`
/// rather than just
/// `printf "%b %c" true 'c'`
///
/// -- When printing arrays, two arguments must be passed; the
/// length of the array fragment to be formatted and the array
/// itself
///
/// -- When extracted, rather than producing a C `printf` (which
/// does not, e.g., support printing of dynamically sized
/// arrays), our `printf` is specialized to a sequence of calls
/// to primitive printers for each supported type
///
/// Before diving into the technical details of how this module works,
/// you might want to see a sample usage at the very end of this file.
open FStar.Char
open FStar.String
open Steel.ST.Util
module L = FStar.List.Tot
module A = Steel.ST.Array
module U32 = FStar.UInt32
#set-options "--ide_id_info_off"
/// `lmbuffer a l` is
/// - an array of `a`
/// - governed by preorders `r` and `s`
/// - with length `l`
inline_for_extraction
let lmbuffer a l =
b: A.array a {
A.length b == U32.v l
}
/// `StTrivial`: A effect abbreviation for a stateful computation
/// with no precondition, and which does not read or change the state
effect StTrivial (a:Type) =
STT a emp (fun _ -> emp)
/// `StBuf a b`: A effect abbreviation for a stateful computation
/// that may read `b` but does not change the state
///
/// NOTE: I need to provide those primitives operating on
/// Steel.ST.Array.ptr instead of Steel.ST.Array.array, otherwise
/// Karamel will complain about arity mismatch
inline_for_extraction
let stBuf (t:Type) : Type =
(l: U32.t) ->
(p: Ghost.erased (lmbuffer t l & perm)) ->
(x: Ghost.erased (Seq.seq t)) ->
(b: A.ptr t) ->
ST unit
(A.pts_to (fst p) (snd p) x)
(fun _ -> A.pts_to (fst p) (snd p) x)
(A.ptr_of (fst p) == b)
(fun _ -> True)
/// Primitive printers for all the types supported by this module
assume val print_string: string -> StTrivial unit
assume val print_char : char -> StTrivial unit
assume val print_u8 : UInt8.t -> StTrivial unit
assume val print_u16 : UInt16.t -> StTrivial unit
assume val print_u32 : UInt32.t -> StTrivial unit
assume val print_u64 : UInt64.t -> StTrivial unit
assume val print_i8 : Int8.t -> StTrivial unit
assume val print_i16 : Int16.t -> StTrivial unit
assume val print_i32 : Int32.t -> StTrivial unit
assume val print_i64 : Int64.t -> StTrivial unit
assume val print_bool : bool -> StTrivial unit
assume val print_lmbuffer_bool : stBuf bool
assume val print_lmbuffer_char : stBuf char
assume val print_lmbuffer_string : stBuf string
assume val print_lmbuffer_u8 : stBuf UInt8.t
assume val print_lmbuffer_u16 : stBuf UInt16.t
assume val print_lmbuffer_u32 : stBuf UInt32.t
assume val print_lmbuffer_u64 : stBuf UInt64.t
assume val print_lmbuffer_i8 : stBuf Int8.t
assume val print_lmbuffer_i16 : stBuf Int16.t
assume val print_lmbuffer_i32 : stBuf Int32.t
assume val print_lmbuffer_i64 : stBuf Int64.t
/// An attribute to control reduction
noextract irreducible
let __printf_reduce__ = unit
/// Base types supported so far
noextract
type base_typ =
| Bool
| Char
| String
| U8
| U16
| U32
| U64
| I8
| I16
| I32
| I64
/// Argument types are base types and arrays thereof
/// Or polymorphic arguments specified by "%a"
noextract
type arg =
| Base of base_typ
| Array of base_typ
| Any
/// Interpreting a `base_typ` as a type
[@@__printf_reduce__]
noextract
let base_typ_as_type (b:base_typ) : Type0 =
match b with
| Bool -> bool
| Char -> char
| String -> string
| U8 -> FStar.UInt8.t
| U16 -> FStar.UInt16.t
| U32 -> FStar.UInt32.t
| U64 -> FStar.UInt64.t
| I8 -> FStar.Int8.t
| I16 -> FStar.Int16.t
| I32 -> FStar.Int32.t
| I64 -> FStar.Int64.t
/// `fragment`: A format string is parsed into a list of fragments of
/// string literals and other arguments that need to be spliced in
/// (interpolated)
noextract
type fragment =
| Frag of string
| Interpolate of arg
noextract
let fragments = list fragment
/// `parse_format s`:
/// Parses a list of characters in a format string into a list of fragments
/// Or None, in case the format string is invalid
[@@__printf_reduce__]
noextract inline_for_extraction
let rec parse_format
(s:list char)
: Tot (option fragments)
(decreases (L.length s))
= let add_dir (d:arg) (ods : option fragments)
= match ods with
| None -> None
| Some ds -> Some (Interpolate d::ds)
in
let head_buffer (ods:option fragments)
= match ods with
| Some (Interpolate (Base t) :: rest) -> Some (Interpolate (Array t) :: rest)
| _ -> None
in
let cons_frag (c:char) (ods:option fragments)
= match ods with
| Some (Frag s::rest) -> Some (Frag (string_of_list (c :: list_of_string s)) :: rest)
| Some rest -> Some (Frag (string_of_list [c]) :: rest)
| _ -> None
in
match s with
| [] -> Some []
| ['%'] -> None
// %a... polymorphic arguments and preceded by their printers
| '%' :: 'a' :: s' ->
add_dir Any (parse_format s')
// %x... arrays of base types
| '%' :: 'x' :: s' ->
head_buffer (parse_format ('%' :: s'))
// %u ... Unsigned integers
| '%' :: 'u' :: s' -> begin
match s' with
| 'y' :: s'' -> add_dir (Base U8) (parse_format s'')
| 's' :: s'' -> add_dir (Base U16) (parse_format s'')
| 'l' :: s'' -> add_dir (Base U32) (parse_format s'')
| 'L' :: s'' -> add_dir (Base U64) (parse_format s'')
| _ -> None
end
| '%' :: c :: s' -> begin
match c with
| '%' -> cons_frag '%' (parse_format s')
| 'b' -> add_dir (Base Bool) (parse_format s')
| 'c' -> add_dir (Base Char) (parse_format s')
| 's' -> add_dir (Base String) (parse_format s')
| 'y' -> add_dir (Base I8) (parse_format s')
| 'i' -> add_dir (Base I16) (parse_format s')
| 'l' -> add_dir (Base I32) (parse_format s')
| 'L' -> add_dir (Base I64) (parse_format s')
| _ -> None
end
| c :: s' ->
cons_frag c (parse_format s')
/// `parse_format_string`: a wrapper around `parse_format`
[@@__printf_reduce__]
noextract inline_for_extraction
let parse_format_string
(s:string)
: option fragments
= parse_format (list_of_string s)
/// `lift a` lifts the type `a` to a higher universe
noextract
type lift (a:Type u#a) : Type u#(max a b) =
| Lift : a -> lift a
/// `done` is a `unit` in universe 1
noextract
let done : lift unit = Lift u#0 u#1 ()
/// `arg_t`: interpreting an argument as a type
/// (in universe 1) since it is polymorphic in the argument type of Any (%a) printers.
/// GM: Somehow, this needs to be a `let rec` (even if it not really recursive)
/// or print_frags fails to verify. I don't know why; the generated
/// VC and its encoding seem identical (modulo hash consing in the
/// latter).
[@@__printf_reduce__]
noextract
let rec arg_t (a:arg) : Type u#1 =
match a with
| Base t -> lift (base_typ_as_type t)
| Array t -> lift ((l:UInt32.t & lmbuffer (base_typ_as_type t) l) & perm & Ghost.erased (Seq.seq (base_typ_as_type t)))
| Any -> (a:Type0 & (a -> StTrivial unit) & a)
/// `frag_t`: a fragment is either a string literal or a argument to be interpolated
noextract
let frag_t = either string (a:arg & arg_t a)
/// `live_frags h l` is a separation logic predicate asserting ownership of all the arrays in `l`
[@@__printf_reduce__; Steel.Effect.Common.__reduce__]
noextract
let live_frag0 (f: frag_t) : vprop =
match f with
| Inl _ -> emp
| Inr a ->
(match a with
| (| Base _, _ |) -> emp
| (| Any, _ |) -> emp
| (| Array _, Lift ((| _, b |), p, v) |) -> A.pts_to b p v)
[@@__printf_reduce__]
noextract
let live_frag (f: frag_t) : vprop =
live_frag0 f
[@@__printf_reduce__]
noextract
let rec live_frags (l:list frag_t) : vprop =
match l with
| [] -> emp
| a :: q -> live_frag a `star` live_frags q
/// `interpret_frags` interprets a list of fragments as a Steel.ST function type
/// Note `l` is the fragments in L-to-R order (i.e., parsing order)
/// `acc` accumulates the fragment values in reverse order
[@@__printf_reduce__]
noextract
let rec interpret_frags (l:fragments) (acc: list frag_t) : Type u#1 =
match l with
| [] ->
// Always a dummy argument at the end
// Ensures that all cases of this match
// have the same universe, i.e., u#1
lift u#0 u#1 unit
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
| Interpolate (Base t) :: args ->
// Base types are simple: we just take one more argument
x:base_typ_as_type t ->
interpret_frags args (Inr (| Base t, Lift x |) :: acc)
| Interpolate (Array t) :: args ->
// Arrays are implicitly polymorphic in their preorders `r` and `s`
// which is what forces us to be in universe 1
// Note, the length `l` is explicit
l:UInt32.t ->
#p:perm ->
#v:Ghost.erased (Seq.seq (base_typ_as_type t)) ->
b:lmbuffer (base_typ_as_type t) l ->
interpret_frags args (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
| Interpolate Any :: args ->
#a:Type0 ->
p:(a -> StTrivial unit) ->
x:a ->
interpret_frags args (Inr (| Any, (| a, p, x |) |) :: acc)
| Frag s :: args ->
// Literal fragments do not incur an additional argument
// We just accumulate them and recur
interpret_frags args (Inl s :: acc)
/// `normal` A normalization marker with very specific steps enabled
noextract unfold
let normal (#a:Type) (x:a) : a =
FStar.Pervasives.norm
[iota;
zeta;
delta_attr [`%__printf_reduce__; `%BigOps.__reduce__];
delta_only [`%Base?; `%Array?; `%Some?; `%Some?.v; `%list_of_string];
primops;
simplify]
x
/// `coerce`: A utility to trigger extensional equality of types
noextract
let coerce (x:'a{'a == 'b}) : 'b = x
/// `fragment_printer`: The type of a printer of fragments
noextract
let fragment_printer =
(acc:list frag_t)
-> STT unit (live_frags acc) (fun _ -> live_frags acc)
/// `print_frags`: Having accumulated all the pieces of a format
/// string and the arguments to the printed (i.e., the `list frag_t`),
/// this function does the actual work of printing them all using the
/// primitive printers
noextract inline_for_extraction
let print_lmbuffer_gen
(#t: Type)
(#fr: frag_t)
(f: stBuf t)
(l: U32.t)
(#tb: Type)
(b: tb)
(p: perm)
(#tv: Type)
(v: tv)
: ST unit (live_frag fr) (fun _ -> live_frag fr)
(tb == lmbuffer t l /\
tv == Ghost.erased (Seq.seq t) /\
live_frag fr == A.pts_to #t (coerce #_ #(lmbuffer t l) b) p (coerce #_ #(Ghost.erased (Seq.seq t)) v))
(fun _ -> True)
= [@inline_let] let b' : lmbuffer t l = coerce b in
let v' : Ghost.erased (Seq.seq t) = coerce v in
let p' : Ghost.erased (lmbuffer t l & perm) = Ghost.hide (b', p) in
rewrite (live_frag fr) (A.pts_to #t (fst p') (snd p') v');
f l _ _ (A.ptr_of b');
rewrite (A.pts_to _ _ _) (live_frag fr)
noextract inline_for_extraction
let print_frag (hd: frag_t) : STT unit (live_frag hd) (fun _ -> live_frag hd)
=
(match hd with
| Inl s -> print_string s
| Inr (| Base t, Lift value |) ->
(match t with
| Bool -> print_bool value
| Char -> print_char value
| String -> print_string value
| U8 -> print_u8 value
| U16 -> print_u16 value
| U32 -> print_u32 value
| U64 -> print_u64 value
| I8 -> print_i8 value
| I16 -> print_i16 value
| I32 -> print_i32 value
| I64 -> print_i64 value)
| Inr (| Array t, Lift ((| l, value |), p, v ) |) ->
(match t with
| Bool -> print_lmbuffer_gen print_lmbuffer_bool l value p v
| Char -> print_lmbuffer_gen print_lmbuffer_char l value p v
| String -> print_lmbuffer_gen print_lmbuffer_string l value p v
| U8 -> print_lmbuffer_gen print_lmbuffer_u8 l value p v
| U16 -> print_lmbuffer_gen print_lmbuffer_u16 l value p v
| U32 -> print_lmbuffer_gen print_lmbuffer_u32 l value p v
| U64 -> print_lmbuffer_gen print_lmbuffer_u64 l value p v
| I8 -> print_lmbuffer_gen print_lmbuffer_i8 l value p v
| I16 -> print_lmbuffer_gen print_lmbuffer_i16 l value p v
| I32 -> print_lmbuffer_gen print_lmbuffer_i32 l value p v
| I64 -> print_lmbuffer_gen print_lmbuffer_i64 l value p v
)
| Inr (| Any, (| _, printer, value |) |) ->
printer value)
noextract inline_for_extraction
let rec print_frags (acc:list frag_t)
: STT unit
(live_frags acc)
(fun _ -> live_frags acc)
= match acc with
| [] -> noop ()
| hd::tl ->
rewrite (live_frags acc) (live_frag hd `star` live_frags tl);
print_frags tl;
print_frag hd;
rewrite (live_frag hd `star` live_frags tl) (live_frags acc)
[@@__printf_reduce__]
let no_inst #a (#b:a -> Type) (f: (#x:a -> b x)) : unit -> #x:a -> b x = fun () -> f
[@@__printf_reduce__]
let elim_unit_arrow #t (f:unit -> t) : t = f ()
/// `aux frags acc`: This is the main workhorse which interprets a
/// parsed format string (`frags`) as a variadic, stateful function
[@@__printf_reduce__]
noextract inline_for_extraction
let rec aux (frags:fragments) (acc:list frag_t) (fp: fragment_printer) : interpret_frags frags acc =
match frags with
| [] ->
let f (l:lift u#0 u#1 unit)
: STT unit (live_frags acc) (fun _ -> live_frags acc)
= fp acc
in
(f <: interpret_frags [] acc)
| Frag s :: rest ->
coerce (aux rest (Inl s :: acc) fp)
| Interpolate (Base t) :: args ->
let f (x:base_typ_as_type t)
: interpret_frags args (Inr (| Base t, Lift x |) :: acc)
= aux args (Inr (| Base t, Lift x |) :: acc) fp
in
f
| Interpolate (Array t) :: rest ->
let f :
l:UInt32.t
-> #p:perm
-> #v:Ghost.erased (Seq.seq (base_typ_as_type t))
-> b:lmbuffer (base_typ_as_type t) l
-> interpret_frags rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc)
= fun l #p #v b -> aux rest (Inr (| Array t, Lift ((| l, b |), p, v) |) :: acc) fp
in
f <: interpret_frags (Interpolate (Array t) :: rest) acc
| Interpolate Any :: rest ->
let f :
unit
-> #a:Type
-> p:(a -> StTrivial unit)
-> x:a
-> interpret_frags rest (Inr (| Any, (| a, p, x |) |) :: acc)
= fun () #a p x -> aux rest (Inr (| Any, (| a, p, x |) |) :: acc) fp
in
elim_unit_arrow (no_inst (f ()) <: (unit -> interpret_frags (Interpolate Any :: rest) acc))
/// `format_string` : A valid format string is one that can be successfully parsed
[@@__printf_reduce__]
noextract
let format_string = s:string{normal #bool (Some? (parse_format_string s))}
/// `interpret_format_string` parses a string into fragments and then
/// interprets it as a type
[@@__printf_reduce__]
noextract
let interpret_format_string (s:format_string) : Type =
interpret_frags (Some?.v (parse_format_string s)) []
/// `printf'`: Almost there ... this has a variadic type
/// and calls the actual printers for all its arguments.
///
/// Note, the `normalize_term` in its body is crucial. It's what
/// allows the term to be specialized at extraction time.
noextract inline_for_extraction
let printf' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] print_frags)
/// `intro_normal_f`: a technical gadget to introduce
/// implicit normalization in the domain and co-domain of a function type
noextract inline_for_extraction
let intro_normal_f (#a:Type) (b: (a -> Type)) (f:(x:a -> b x))
: (x:(normal a) -> normal (b x))
= f
/// `printf`: The main function has type
/// `s:normal format_string -> normal (interpret_format_string s)`
/// Note:
/// This is the type F* infers for it and it is best to leave it that way
/// rather then writing it down and asking F* to re-check what it inferred.
///
/// Annotating it results in a needless additional proof obligation to
/// equate types after they are partially reduced, which is pointless.
noextract inline_for_extraction
val printf : s:normal format_string -> normal (interpret_format_string s)
let printf = intro_normal_f #format_string interpret_format_string printf'
/// `skip`: We also provide `skip`, a function that has the same type as printf
/// but normalizes to `()`, i.e., it prints nothing. This is useful for conditional
/// printing in debug code, for instance.
noextract inline_for_extraction
let skip' (s:format_string) : interpret_format_string s =
normalize_term
(match parse_format_string s with
| Some frags -> aux frags [] (fun _ -> noop ()))
noextract inline_for_extraction
val skip : s:normal format_string -> normal (interpret_format_string s)
let skip = intro_normal_f #format_string interpret_format_string skip'
/// `test`: A small test function
/// Running `fstar --codegen OCaml Steel.ST.Printf.fst --extract Steel.ST.Printf`
/// produces the following for the body of this function
/// ```
/// print_string "Hello ";
/// print_bool true;
/// print_string " Steel.ST ";
/// print_u64 m;
/// print_string " Printf ";
/// print_lmbuffer_bool l x () ();
/// print_string " ";
/// print_string "bye" | {
"checked_file": "/",
"dependencies": [
"Steel.ST.Util.fsti.checked",
"Steel.ST.Array.fsti.checked",
"Steel.Effect.Common.fsti.checked",
"prims.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.UInt16.fsti.checked",
"FStar.String.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.List.Tot.fst.checked",
"FStar.Int8.fsti.checked",
"FStar.Int64.fsti.checked",
"FStar.Int32.fsti.checked",
"FStar.Int16.fsti.checked",
"FStar.Ghost.fsti.checked",
"FStar.Char.fsti.checked",
"FStar.BigOps.fsti.checked"
],
"interface_file": false,
"source_file": "Steel.ST.Printf.fst"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "Steel.ST.Array",
"short_module": "A"
},
{
"abbrev": true,
"full_module": "FStar.List.Tot",
"short_module": "L"
},
{
"abbrev": false,
"full_module": "Steel.ST.Util",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.String",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Char",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Steel.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
m: FStar.UInt64.t ->
l: FStar.UInt32.t ->
x: Steel.ST.Array.array Prims.bool {Steel.ST.Array.length x == FStar.UInt32.v l} ->
v: FStar.Ghost.erased (FStar.Seq.Base.seq Prims.bool)
-> Steel.ST.Effect.STT Prims.unit | Steel.ST.Effect.STT | [] | [] | [
"FStar.UInt64.t",
"FStar.UInt32.t",
"Steel.ST.Array.array",
"Prims.bool",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt.size",
"FStar.UInt32.n",
"Steel.ST.Array.length",
"FStar.UInt32.v",
"FStar.Ghost.erased",
"FStar.Seq.Base.seq",
"Steel.ST.Printf.printf",
"Steel.FractionalPermission.full_perm",
"Steel.ST.Printf.done",
"Prims.unit",
"Steel.ST.Array.pts_to",
"FStar.Ghost.reveal",
"Steel.Effect.Common.vprop"
] | [] | false | true | false | false | false | let test_printf
(m: UInt64.t)
(l: UInt32.t)
(x: A.array bool {A.length x == U32.v l})
(v: Ghost.erased (Seq.seq bool))
: STT unit (A.pts_to x full_perm v) (fun _ -> A.pts_to x full_perm v) =
| printf "Hello %b Steel.ST %uL Printf %xb %s" true m l x "bye" done | false |
LowParse.SLow.BoundedInt.fsti | LowParse.SLow.BoundedInt.parse32_bounded_integer | val parse32_bounded_integer (sz: integer_size) : Tot (parser32 (parse_bounded_integer sz)) | val parse32_bounded_integer (sz: integer_size) : Tot (parser32 (parse_bounded_integer sz)) | let parse32_bounded_integer (sz: integer_size) : Tot (parser32 (parse_bounded_integer sz))
= match sz with
| 1 -> parse32_bounded_integer_1
| 2 -> parse32_bounded_integer_2
| 3 -> parse32_bounded_integer_3
| 4 -> parse32_bounded_integer_4 | {
"file_name": "src/lowparse/LowParse.SLow.BoundedInt.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 34,
"end_line": 30,
"start_col": 0,
"start_line": 25
} | module LowParse.SLow.BoundedInt
include LowParse.Spec.BoundedInt
include LowParse.SLow.Base
(* bounded integers *)
inline_for_extraction
val parse32_bounded_integer_1
: (parser32 (parse_bounded_integer 1))
inline_for_extraction
val parse32_bounded_integer_2
: (parser32 (parse_bounded_integer 2))
inline_for_extraction
val parse32_bounded_integer_3
: (parser32 (parse_bounded_integer 3))
inline_for_extraction
val parse32_bounded_integer_4
: (parser32 (parse_bounded_integer 4))
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.SLow.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.BoundedInt.fsti"
} | [
{
"abbrev": false,
"full_module": "LowParse.SLow.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | sz: LowParse.Spec.BoundedInt.integer_size
-> LowParse.SLow.Base.parser32 (LowParse.Spec.BoundedInt.parse_bounded_integer sz) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.SLow.BoundedInt.parse32_bounded_integer_1",
"LowParse.SLow.BoundedInt.parse32_bounded_integer_2",
"LowParse.SLow.BoundedInt.parse32_bounded_integer_3",
"LowParse.SLow.BoundedInt.parse32_bounded_integer_4",
"LowParse.SLow.Base.parser32",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.BoundedInt.parse_bounded_integer"
] | [] | false | false | false | false | false | let parse32_bounded_integer (sz: integer_size) : Tot (parser32 (parse_bounded_integer sz)) =
| match sz with
| 1 -> parse32_bounded_integer_1
| 2 -> parse32_bounded_integer_2
| 3 -> parse32_bounded_integer_3
| 4 -> parse32_bounded_integer_4 | false |
LowParse.SLow.BoundedInt.fsti | LowParse.SLow.BoundedInt.size32_u32_le | val size32_u32_le:size32 serialize_u32_le | val size32_u32_le:size32 serialize_u32_le | let size32_u32_le: size32 serialize_u32_le =
assert_norm (size32_constant_precond serialize_u32_le 4ul);
size32_constant serialize_u32_le 4ul () | {
"file_name": "src/lowparse/LowParse.SLow.BoundedInt.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 41,
"end_line": 129,
"start_col": 0,
"start_line": 127
} | module LowParse.SLow.BoundedInt
include LowParse.Spec.BoundedInt
include LowParse.SLow.Base
(* bounded integers *)
inline_for_extraction
val parse32_bounded_integer_1
: (parser32 (parse_bounded_integer 1))
inline_for_extraction
val parse32_bounded_integer_2
: (parser32 (parse_bounded_integer 2))
inline_for_extraction
val parse32_bounded_integer_3
: (parser32 (parse_bounded_integer 3))
inline_for_extraction
val parse32_bounded_integer_4
: (parser32 (parse_bounded_integer 4))
inline_for_extraction
noextract
let parse32_bounded_integer (sz: integer_size) : Tot (parser32 (parse_bounded_integer sz))
= match sz with
| 1 -> parse32_bounded_integer_1
| 2 -> parse32_bounded_integer_2
| 3 -> parse32_bounded_integer_3
| 4 -> parse32_bounded_integer_4
inline_for_extraction
val serialize32_bounded_integer_1
: (serializer32 (serialize_bounded_integer 1))
inline_for_extraction
val serialize32_bounded_integer_2
: (serializer32 (serialize_bounded_integer 2))
inline_for_extraction
val serialize32_bounded_integer_3
: (serializer32 (serialize_bounded_integer 3))
inline_for_extraction
val serialize32_bounded_integer_4
: (serializer32 (serialize_bounded_integer 4))
inline_for_extraction
noextract
let serialize32_bounded_integer
(sz: integer_size)
: Tot (serializer32 (serialize_bounded_integer sz))
= match sz with
| 1 -> serialize32_bounded_integer_1
| 2 -> serialize32_bounded_integer_2
| 3 -> serialize32_bounded_integer_3
| 4 -> serialize32_bounded_integer_4
#push-options "--max_fuel 0"
inline_for_extraction
val parse32_bounded_integer_le_1
: parser32 (parse_bounded_integer_le 1)
inline_for_extraction
val parse32_bounded_integer_le_2
: parser32 (parse_bounded_integer_le 2)
inline_for_extraction
val parse32_bounded_integer_le_3
: parser32 (parse_bounded_integer_le 3)
inline_for_extraction
val parse32_bounded_integer_le_4
: parser32 (parse_bounded_integer_le 4)
inline_for_extraction
noextract
let parse32_bounded_integer_le (sz: integer_size) : Tot (parser32 (parse_bounded_integer_le sz))
= match sz with
| 1 -> parse32_bounded_integer_le_1
| 2 -> parse32_bounded_integer_le_2
| 3 -> parse32_bounded_integer_le_3
| 4 -> parse32_bounded_integer_le_4
inline_for_extraction
val parse32_u16_le : parser32 parse_u16_le
inline_for_extraction
val parse32_u32_le : parser32 parse_u32_le
#pop-options
inline_for_extraction
val serialize32_bounded_integer_le_1 : serializer32 (serialize_bounded_integer_le 1)
inline_for_extraction
val serialize32_bounded_integer_le_2 : serializer32 (serialize_bounded_integer_le 2)
inline_for_extraction
val serialize32_bounded_integer_le_3 : serializer32 (serialize_bounded_integer_le 3)
inline_for_extraction
val serialize32_bounded_integer_le_4 : serializer32 (serialize_bounded_integer_le 4)
inline_for_extraction
noextract
let serialize32_bounded_integer_le (sz: integer_size) : Tot (serializer32 (serialize_bounded_integer_le sz))
= match sz with
| 1 -> serialize32_bounded_integer_le_1
| 2 -> serialize32_bounded_integer_le_2
| 3 -> serialize32_bounded_integer_le_3
| 4 -> serialize32_bounded_integer_le_4
inline_for_extraction
val serialize32_u16_le : serializer32 serialize_u16_le
inline_for_extraction
val serialize32_u32_le : serializer32 serialize_u32_le
inline_for_extraction
let size32_u16_le: size32 serialize_u16_le =
assert_norm (size32_constant_precond serialize_u16_le 2ul);
size32_constant serialize_u16_le 2ul () | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.SLow.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.BoundedInt.fsti"
} | [
{
"abbrev": false,
"full_module": "LowParse.SLow.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.SLow.Base.size32 LowParse.Spec.BoundedInt.serialize_u32_le | Prims.Tot | [
"total"
] | [] | [
"LowParse.SLow.Base.size32_constant",
"LowParse.Spec.Int.parse_u32_kind",
"FStar.UInt32.t",
"LowParse.Spec.BoundedInt.parse_u32_le",
"LowParse.Spec.BoundedInt.serialize_u32_le",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"LowParse.SLow.Base.size32_constant_precond"
] | [] | false | false | false | true | false | let size32_u32_le:size32 serialize_u32_le =
| assert_norm (size32_constant_precond serialize_u32_le 4ul);
size32_constant serialize_u32_le 4ul () | false |
LowParse.SLow.BoundedInt.fsti | LowParse.SLow.BoundedInt.parse32_bounded_integer_le | val parse32_bounded_integer_le (sz: integer_size) : Tot (parser32 (parse_bounded_integer_le sz)) | val parse32_bounded_integer_le (sz: integer_size) : Tot (parser32 (parse_bounded_integer_le sz)) | let parse32_bounded_integer_le (sz: integer_size) : Tot (parser32 (parse_bounded_integer_le sz))
= match sz with
| 1 -> parse32_bounded_integer_le_1
| 2 -> parse32_bounded_integer_le_2
| 3 -> parse32_bounded_integer_le_3
| 4 -> parse32_bounded_integer_le_4 | {
"file_name": "src/lowparse/LowParse.SLow.BoundedInt.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 37,
"end_line": 84,
"start_col": 0,
"start_line": 79
} | module LowParse.SLow.BoundedInt
include LowParse.Spec.BoundedInt
include LowParse.SLow.Base
(* bounded integers *)
inline_for_extraction
val parse32_bounded_integer_1
: (parser32 (parse_bounded_integer 1))
inline_for_extraction
val parse32_bounded_integer_2
: (parser32 (parse_bounded_integer 2))
inline_for_extraction
val parse32_bounded_integer_3
: (parser32 (parse_bounded_integer 3))
inline_for_extraction
val parse32_bounded_integer_4
: (parser32 (parse_bounded_integer 4))
inline_for_extraction
noextract
let parse32_bounded_integer (sz: integer_size) : Tot (parser32 (parse_bounded_integer sz))
= match sz with
| 1 -> parse32_bounded_integer_1
| 2 -> parse32_bounded_integer_2
| 3 -> parse32_bounded_integer_3
| 4 -> parse32_bounded_integer_4
inline_for_extraction
val serialize32_bounded_integer_1
: (serializer32 (serialize_bounded_integer 1))
inline_for_extraction
val serialize32_bounded_integer_2
: (serializer32 (serialize_bounded_integer 2))
inline_for_extraction
val serialize32_bounded_integer_3
: (serializer32 (serialize_bounded_integer 3))
inline_for_extraction
val serialize32_bounded_integer_4
: (serializer32 (serialize_bounded_integer 4))
inline_for_extraction
noextract
let serialize32_bounded_integer
(sz: integer_size)
: Tot (serializer32 (serialize_bounded_integer sz))
= match sz with
| 1 -> serialize32_bounded_integer_1
| 2 -> serialize32_bounded_integer_2
| 3 -> serialize32_bounded_integer_3
| 4 -> serialize32_bounded_integer_4
#push-options "--max_fuel 0"
inline_for_extraction
val parse32_bounded_integer_le_1
: parser32 (parse_bounded_integer_le 1)
inline_for_extraction
val parse32_bounded_integer_le_2
: parser32 (parse_bounded_integer_le 2)
inline_for_extraction
val parse32_bounded_integer_le_3
: parser32 (parse_bounded_integer_le 3)
inline_for_extraction
val parse32_bounded_integer_le_4
: parser32 (parse_bounded_integer_le 4)
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.SLow.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.BoundedInt.fsti"
} | [
{
"abbrev": false,
"full_module": "LowParse.SLow.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 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": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | sz: LowParse.Spec.BoundedInt.integer_size
-> LowParse.SLow.Base.parser32 (LowParse.Spec.BoundedInt.parse_bounded_integer_le sz) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.SLow.BoundedInt.parse32_bounded_integer_le_1",
"LowParse.SLow.BoundedInt.parse32_bounded_integer_le_2",
"LowParse.SLow.BoundedInt.parse32_bounded_integer_le_3",
"LowParse.SLow.BoundedInt.parse32_bounded_integer_le_4",
"LowParse.SLow.Base.parser32",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.BoundedInt.parse_bounded_integer_le"
] | [] | false | false | false | false | false | let parse32_bounded_integer_le (sz: integer_size) : Tot (parser32 (parse_bounded_integer_le sz)) =
| match sz with
| 1 -> parse32_bounded_integer_le_1
| 2 -> parse32_bounded_integer_le_2
| 3 -> parse32_bounded_integer_le_3
| 4 -> parse32_bounded_integer_le_4 | false |
LowParse.SLow.BoundedInt.fsti | LowParse.SLow.BoundedInt.size32_u16_le | val size32_u16_le:size32 serialize_u16_le | val size32_u16_le:size32 serialize_u16_le | let size32_u16_le: size32 serialize_u16_le =
assert_norm (size32_constant_precond serialize_u16_le 2ul);
size32_constant serialize_u16_le 2ul () | {
"file_name": "src/lowparse/LowParse.SLow.BoundedInt.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 41,
"end_line": 124,
"start_col": 0,
"start_line": 122
} | module LowParse.SLow.BoundedInt
include LowParse.Spec.BoundedInt
include LowParse.SLow.Base
(* bounded integers *)
inline_for_extraction
val parse32_bounded_integer_1
: (parser32 (parse_bounded_integer 1))
inline_for_extraction
val parse32_bounded_integer_2
: (parser32 (parse_bounded_integer 2))
inline_for_extraction
val parse32_bounded_integer_3
: (parser32 (parse_bounded_integer 3))
inline_for_extraction
val parse32_bounded_integer_4
: (parser32 (parse_bounded_integer 4))
inline_for_extraction
noextract
let parse32_bounded_integer (sz: integer_size) : Tot (parser32 (parse_bounded_integer sz))
= match sz with
| 1 -> parse32_bounded_integer_1
| 2 -> parse32_bounded_integer_2
| 3 -> parse32_bounded_integer_3
| 4 -> parse32_bounded_integer_4
inline_for_extraction
val serialize32_bounded_integer_1
: (serializer32 (serialize_bounded_integer 1))
inline_for_extraction
val serialize32_bounded_integer_2
: (serializer32 (serialize_bounded_integer 2))
inline_for_extraction
val serialize32_bounded_integer_3
: (serializer32 (serialize_bounded_integer 3))
inline_for_extraction
val serialize32_bounded_integer_4
: (serializer32 (serialize_bounded_integer 4))
inline_for_extraction
noextract
let serialize32_bounded_integer
(sz: integer_size)
: Tot (serializer32 (serialize_bounded_integer sz))
= match sz with
| 1 -> serialize32_bounded_integer_1
| 2 -> serialize32_bounded_integer_2
| 3 -> serialize32_bounded_integer_3
| 4 -> serialize32_bounded_integer_4
#push-options "--max_fuel 0"
inline_for_extraction
val parse32_bounded_integer_le_1
: parser32 (parse_bounded_integer_le 1)
inline_for_extraction
val parse32_bounded_integer_le_2
: parser32 (parse_bounded_integer_le 2)
inline_for_extraction
val parse32_bounded_integer_le_3
: parser32 (parse_bounded_integer_le 3)
inline_for_extraction
val parse32_bounded_integer_le_4
: parser32 (parse_bounded_integer_le 4)
inline_for_extraction
noextract
let parse32_bounded_integer_le (sz: integer_size) : Tot (parser32 (parse_bounded_integer_le sz))
= match sz with
| 1 -> parse32_bounded_integer_le_1
| 2 -> parse32_bounded_integer_le_2
| 3 -> parse32_bounded_integer_le_3
| 4 -> parse32_bounded_integer_le_4
inline_for_extraction
val parse32_u16_le : parser32 parse_u16_le
inline_for_extraction
val parse32_u32_le : parser32 parse_u32_le
#pop-options
inline_for_extraction
val serialize32_bounded_integer_le_1 : serializer32 (serialize_bounded_integer_le 1)
inline_for_extraction
val serialize32_bounded_integer_le_2 : serializer32 (serialize_bounded_integer_le 2)
inline_for_extraction
val serialize32_bounded_integer_le_3 : serializer32 (serialize_bounded_integer_le 3)
inline_for_extraction
val serialize32_bounded_integer_le_4 : serializer32 (serialize_bounded_integer_le 4)
inline_for_extraction
noextract
let serialize32_bounded_integer_le (sz: integer_size) : Tot (serializer32 (serialize_bounded_integer_le sz))
= match sz with
| 1 -> serialize32_bounded_integer_le_1
| 2 -> serialize32_bounded_integer_le_2
| 3 -> serialize32_bounded_integer_le_3
| 4 -> serialize32_bounded_integer_le_4
inline_for_extraction
val serialize32_u16_le : serializer32 serialize_u16_le
inline_for_extraction
val serialize32_u32_le : serializer32 serialize_u32_le | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.SLow.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.BoundedInt.fsti"
} | [
{
"abbrev": false,
"full_module": "LowParse.SLow.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | LowParse.SLow.Base.size32 LowParse.Spec.BoundedInt.serialize_u16_le | Prims.Tot | [
"total"
] | [] | [
"LowParse.SLow.Base.size32_constant",
"LowParse.Spec.Int.parse_u16_kind",
"FStar.UInt16.t",
"LowParse.Spec.BoundedInt.parse_u16_le",
"LowParse.Spec.BoundedInt.serialize_u16_le",
"FStar.UInt32.__uint_to_t",
"Prims.unit",
"FStar.Pervasives.assert_norm",
"LowParse.SLow.Base.size32_constant_precond"
] | [] | false | false | false | true | false | let size32_u16_le:size32 serialize_u16_le =
| assert_norm (size32_constant_precond serialize_u16_le 2ul);
size32_constant serialize_u16_le 2ul () | false |
LowParse.SLow.BoundedInt.fsti | LowParse.SLow.BoundedInt.serialize32_bounded_integer_le | val serialize32_bounded_integer_le (sz: integer_size)
: Tot (serializer32 (serialize_bounded_integer_le sz)) | val serialize32_bounded_integer_le (sz: integer_size)
: Tot (serializer32 (serialize_bounded_integer_le sz)) | let serialize32_bounded_integer_le (sz: integer_size) : Tot (serializer32 (serialize_bounded_integer_le sz))
= match sz with
| 1 -> serialize32_bounded_integer_le_1
| 2 -> serialize32_bounded_integer_le_2
| 3 -> serialize32_bounded_integer_le_3
| 4 -> serialize32_bounded_integer_le_4 | {
"file_name": "src/lowparse/LowParse.SLow.BoundedInt.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 41,
"end_line": 113,
"start_col": 0,
"start_line": 108
} | module LowParse.SLow.BoundedInt
include LowParse.Spec.BoundedInt
include LowParse.SLow.Base
(* bounded integers *)
inline_for_extraction
val parse32_bounded_integer_1
: (parser32 (parse_bounded_integer 1))
inline_for_extraction
val parse32_bounded_integer_2
: (parser32 (parse_bounded_integer 2))
inline_for_extraction
val parse32_bounded_integer_3
: (parser32 (parse_bounded_integer 3))
inline_for_extraction
val parse32_bounded_integer_4
: (parser32 (parse_bounded_integer 4))
inline_for_extraction
noextract
let parse32_bounded_integer (sz: integer_size) : Tot (parser32 (parse_bounded_integer sz))
= match sz with
| 1 -> parse32_bounded_integer_1
| 2 -> parse32_bounded_integer_2
| 3 -> parse32_bounded_integer_3
| 4 -> parse32_bounded_integer_4
inline_for_extraction
val serialize32_bounded_integer_1
: (serializer32 (serialize_bounded_integer 1))
inline_for_extraction
val serialize32_bounded_integer_2
: (serializer32 (serialize_bounded_integer 2))
inline_for_extraction
val serialize32_bounded_integer_3
: (serializer32 (serialize_bounded_integer 3))
inline_for_extraction
val serialize32_bounded_integer_4
: (serializer32 (serialize_bounded_integer 4))
inline_for_extraction
noextract
let serialize32_bounded_integer
(sz: integer_size)
: Tot (serializer32 (serialize_bounded_integer sz))
= match sz with
| 1 -> serialize32_bounded_integer_1
| 2 -> serialize32_bounded_integer_2
| 3 -> serialize32_bounded_integer_3
| 4 -> serialize32_bounded_integer_4
#push-options "--max_fuel 0"
inline_for_extraction
val parse32_bounded_integer_le_1
: parser32 (parse_bounded_integer_le 1)
inline_for_extraction
val parse32_bounded_integer_le_2
: parser32 (parse_bounded_integer_le 2)
inline_for_extraction
val parse32_bounded_integer_le_3
: parser32 (parse_bounded_integer_le 3)
inline_for_extraction
val parse32_bounded_integer_le_4
: parser32 (parse_bounded_integer_le 4)
inline_for_extraction
noextract
let parse32_bounded_integer_le (sz: integer_size) : Tot (parser32 (parse_bounded_integer_le sz))
= match sz with
| 1 -> parse32_bounded_integer_le_1
| 2 -> parse32_bounded_integer_le_2
| 3 -> parse32_bounded_integer_le_3
| 4 -> parse32_bounded_integer_le_4
inline_for_extraction
val parse32_u16_le : parser32 parse_u16_le
inline_for_extraction
val parse32_u32_le : parser32 parse_u32_le
#pop-options
inline_for_extraction
val serialize32_bounded_integer_le_1 : serializer32 (serialize_bounded_integer_le 1)
inline_for_extraction
val serialize32_bounded_integer_le_2 : serializer32 (serialize_bounded_integer_le 2)
inline_for_extraction
val serialize32_bounded_integer_le_3 : serializer32 (serialize_bounded_integer_le 3)
inline_for_extraction
val serialize32_bounded_integer_le_4 : serializer32 (serialize_bounded_integer_le 4)
inline_for_extraction | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.SLow.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.BoundedInt.fsti"
} | [
{
"abbrev": false,
"full_module": "LowParse.SLow.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false | sz: LowParse.Spec.BoundedInt.integer_size
-> LowParse.SLow.Base.serializer32 (LowParse.Spec.BoundedInt.serialize_bounded_integer_le sz) | Prims.Tot | [
"total"
] | [] | [
"LowParse.Spec.BoundedInt.integer_size",
"LowParse.SLow.BoundedInt.serialize32_bounded_integer_le_1",
"LowParse.SLow.BoundedInt.serialize32_bounded_integer_le_2",
"LowParse.SLow.BoundedInt.serialize32_bounded_integer_le_3",
"LowParse.SLow.BoundedInt.serialize32_bounded_integer_le_4",
"LowParse.SLow.Base.serializer32",
"LowParse.Spec.BoundedInt.parse_bounded_integer_kind",
"LowParse.Spec.BoundedInt.bounded_integer",
"LowParse.Spec.BoundedInt.parse_bounded_integer_le",
"LowParse.Spec.BoundedInt.serialize_bounded_integer_le"
] | [] | false | false | false | false | false | let serialize32_bounded_integer_le (sz: integer_size)
: Tot (serializer32 (serialize_bounded_integer_le sz)) =
| match sz with
| 1 -> serialize32_bounded_integer_le_1
| 2 -> serialize32_bounded_integer_le_2
| 3 -> serialize32_bounded_integer_le_3
| 4 -> serialize32_bounded_integer_le_4 | false |
LowParse.SLow.BoundedInt.fsti | LowParse.SLow.BoundedInt.parse32_bounded_int32_le | val parse32_bounded_int32_le
(min32: U32.t)
(max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296})
: Tot (parser32 (parse_bounded_int32_le (U32.v min32) (U32.v max32))) | val parse32_bounded_int32_le
(min32: U32.t)
(max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296})
: Tot (parser32 (parse_bounded_int32_le (U32.v min32) (U32.v max32))) | let parse32_bounded_int32_le
(min32: U32.t)
(max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 })
: Tot (parser32 (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
= fun input -> (
if max32 `U32.lt` 256ul
then parse32_bounded_int32_le_1 min32 max32 input
else if max32 `U32.lt` 65536ul
then parse32_bounded_int32_le_2 min32 max32 input
else if max32 `U32.lt` 16777216ul
then parse32_bounded_int32_le_3 min32 max32 input
else parse32_bounded_int32_le_4 min32 max32 input
) | {
"file_name": "src/lowparse/LowParse.SLow.BoundedInt.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 237,
"start_col": 0,
"start_line": 225
} | module LowParse.SLow.BoundedInt
include LowParse.Spec.BoundedInt
include LowParse.SLow.Base
(* bounded integers *)
inline_for_extraction
val parse32_bounded_integer_1
: (parser32 (parse_bounded_integer 1))
inline_for_extraction
val parse32_bounded_integer_2
: (parser32 (parse_bounded_integer 2))
inline_for_extraction
val parse32_bounded_integer_3
: (parser32 (parse_bounded_integer 3))
inline_for_extraction
val parse32_bounded_integer_4
: (parser32 (parse_bounded_integer 4))
inline_for_extraction
noextract
let parse32_bounded_integer (sz: integer_size) : Tot (parser32 (parse_bounded_integer sz))
= match sz with
| 1 -> parse32_bounded_integer_1
| 2 -> parse32_bounded_integer_2
| 3 -> parse32_bounded_integer_3
| 4 -> parse32_bounded_integer_4
inline_for_extraction
val serialize32_bounded_integer_1
: (serializer32 (serialize_bounded_integer 1))
inline_for_extraction
val serialize32_bounded_integer_2
: (serializer32 (serialize_bounded_integer 2))
inline_for_extraction
val serialize32_bounded_integer_3
: (serializer32 (serialize_bounded_integer 3))
inline_for_extraction
val serialize32_bounded_integer_4
: (serializer32 (serialize_bounded_integer 4))
inline_for_extraction
noextract
let serialize32_bounded_integer
(sz: integer_size)
: Tot (serializer32 (serialize_bounded_integer sz))
= match sz with
| 1 -> serialize32_bounded_integer_1
| 2 -> serialize32_bounded_integer_2
| 3 -> serialize32_bounded_integer_3
| 4 -> serialize32_bounded_integer_4
#push-options "--max_fuel 0"
inline_for_extraction
val parse32_bounded_integer_le_1
: parser32 (parse_bounded_integer_le 1)
inline_for_extraction
val parse32_bounded_integer_le_2
: parser32 (parse_bounded_integer_le 2)
inline_for_extraction
val parse32_bounded_integer_le_3
: parser32 (parse_bounded_integer_le 3)
inline_for_extraction
val parse32_bounded_integer_le_4
: parser32 (parse_bounded_integer_le 4)
inline_for_extraction
noextract
let parse32_bounded_integer_le (sz: integer_size) : Tot (parser32 (parse_bounded_integer_le sz))
= match sz with
| 1 -> parse32_bounded_integer_le_1
| 2 -> parse32_bounded_integer_le_2
| 3 -> parse32_bounded_integer_le_3
| 4 -> parse32_bounded_integer_le_4
inline_for_extraction
val parse32_u16_le : parser32 parse_u16_le
inline_for_extraction
val parse32_u32_le : parser32 parse_u32_le
#pop-options
inline_for_extraction
val serialize32_bounded_integer_le_1 : serializer32 (serialize_bounded_integer_le 1)
inline_for_extraction
val serialize32_bounded_integer_le_2 : serializer32 (serialize_bounded_integer_le 2)
inline_for_extraction
val serialize32_bounded_integer_le_3 : serializer32 (serialize_bounded_integer_le 3)
inline_for_extraction
val serialize32_bounded_integer_le_4 : serializer32 (serialize_bounded_integer_le 4)
inline_for_extraction
noextract
let serialize32_bounded_integer_le (sz: integer_size) : Tot (serializer32 (serialize_bounded_integer_le sz))
= match sz with
| 1 -> serialize32_bounded_integer_le_1
| 2 -> serialize32_bounded_integer_le_2
| 3 -> serialize32_bounded_integer_le_3
| 4 -> serialize32_bounded_integer_le_4
inline_for_extraction
val serialize32_u16_le : serializer32 serialize_u16_le
inline_for_extraction
val serialize32_u32_le : serializer32 serialize_u32_le
inline_for_extraction
let size32_u16_le: size32 serialize_u16_le =
assert_norm (size32_constant_precond serialize_u16_le 2ul);
size32_constant serialize_u16_le 2ul ()
inline_for_extraction
let size32_u32_le: size32 serialize_u32_le =
assert_norm (size32_constant_precond serialize_u32_le 4ul);
size32_constant serialize_u32_le 4ul ()
module U32 = FStar.UInt32
val parse32_bounded_int32_1
(min32: U32.t)
(max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 })
: Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val parse32_bounded_int32_2
(min32: U32.t)
(max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 })
: Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val parse32_bounded_int32_3
(min32: U32.t)
(max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 })
: Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val parse32_bounded_int32_4
(min32: U32.t)
(max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 })
: Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32)))
inline_for_extraction
let parse32_bounded_int32
(min32: U32.t)
(max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 })
: Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32)))
= fun input -> (
if max32 `U32.lt` 256ul
then parse32_bounded_int32_1 min32 max32 input
else if max32 `U32.lt` 65536ul
then parse32_bounded_int32_2 min32 max32 input
else if max32 `U32.lt` 16777216ul
then parse32_bounded_int32_3 min32 max32 input
else parse32_bounded_int32_4 min32 max32 input
)
val serialize32_bounded_int32_1
(min32: U32.t)
(max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 })
: Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
val serialize32_bounded_int32_2
(min32: U32.t)
(max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 })
: Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
val serialize32_bounded_int32_3
(min32: U32.t)
(max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 })
: Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
val serialize32_bounded_int32_4
(min32: U32.t)
(max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 })
: Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
inline_for_extraction
let serialize32_bounded_int32
(min32: U32.t)
(max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 })
: Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
= fun input -> (
if max32 `U32.lt` 256ul
then serialize32_bounded_int32_1 min32 max32 input
else if max32 `U32.lt` 65536ul
then serialize32_bounded_int32_2 min32 max32 input
else if max32 `U32.lt` 16777216ul
then serialize32_bounded_int32_3 min32 max32 input
else serialize32_bounded_int32_4 min32 max32 input
)
val parse32_bounded_int32_le_1
(min32: U32.t)
(max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 })
: Tot (parser32 (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val parse32_bounded_int32_le_2
(min32: U32.t)
(max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 })
: Tot (parser32 (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val parse32_bounded_int32_le_3
(min32: U32.t)
(max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 })
: Tot (parser32 (parse_bounded_int32_le (U32.v min32) (U32.v max32)))
val parse32_bounded_int32_le_4
(min32: U32.t)
(max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 })
: Tot (parser32 (parse_bounded_int32_le (U32.v min32) (U32.v max32))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.SLow.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.BoundedInt.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min32: FStar.UInt32.t ->
max32:
FStar.UInt32.t
{ 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\
FStar.UInt32.v max32 < 4294967296 }
-> LowParse.SLow.Base.parser32 (LowParse.Spec.BoundedInt.parse_bounded_int32_le (FStar.UInt32.v min32
)
(FStar.UInt32.v max32)) | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"Prims.op_LessThanOrEqual",
"LowParse.SLow.Base.bytes32",
"FStar.UInt32.lt",
"FStar.UInt32.__uint_to_t",
"LowParse.SLow.BoundedInt.parse32_bounded_int32_le_1",
"Prims.bool",
"LowParse.SLow.BoundedInt.parse32_bounded_int32_le_2",
"LowParse.SLow.BoundedInt.parse32_bounded_int32_le_3",
"LowParse.SLow.BoundedInt.parse32_bounded_int32_le_4",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.BoundedInt.bounded_int32",
"LowParse.SLow.Base.parser32_correct",
"LowParse.Spec.BoundedInt.parse_bounded_int32_kind",
"LowParse.Spec.BoundedInt.parse_bounded_int32_le",
"LowParse.SLow.Base.parser32"
] | [] | false | false | false | false | false | let parse32_bounded_int32_le
(min32: U32.t)
(max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296})
: Tot (parser32 (parse_bounded_int32_le (U32.v min32) (U32.v max32))) =
| fun input ->
(if max32 `U32.lt` 256ul
then parse32_bounded_int32_le_1 min32 max32 input
else
if max32 `U32.lt` 65536ul
then parse32_bounded_int32_le_2 min32 max32 input
else
if max32 `U32.lt` 16777216ul
then parse32_bounded_int32_le_3 min32 max32 input
else parse32_bounded_int32_le_4 min32 max32 input) | false |
LowParse.SLow.BoundedInt.fsti | LowParse.SLow.BoundedInt.serialize32_bounded_int32 | val serialize32_bounded_int32
(min32: U32.t)
(max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296})
: Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32))) | val serialize32_bounded_int32
(min32: U32.t)
(max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296})
: Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32))) | let serialize32_bounded_int32
(min32: U32.t)
(max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 })
: Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
= fun input -> (
if max32 `U32.lt` 256ul
then serialize32_bounded_int32_1 min32 max32 input
else if max32 `U32.lt` 65536ul
then serialize32_bounded_int32_2 min32 max32 input
else if max32 `U32.lt` 16777216ul
then serialize32_bounded_int32_3 min32 max32 input
else serialize32_bounded_int32_4 min32 max32 input
) | {
"file_name": "src/lowparse/LowParse.SLow.BoundedInt.fsti",
"git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | {
"end_col": 3,
"end_line": 201,
"start_col": 0,
"start_line": 189
} | module LowParse.SLow.BoundedInt
include LowParse.Spec.BoundedInt
include LowParse.SLow.Base
(* bounded integers *)
inline_for_extraction
val parse32_bounded_integer_1
: (parser32 (parse_bounded_integer 1))
inline_for_extraction
val parse32_bounded_integer_2
: (parser32 (parse_bounded_integer 2))
inline_for_extraction
val parse32_bounded_integer_3
: (parser32 (parse_bounded_integer 3))
inline_for_extraction
val parse32_bounded_integer_4
: (parser32 (parse_bounded_integer 4))
inline_for_extraction
noextract
let parse32_bounded_integer (sz: integer_size) : Tot (parser32 (parse_bounded_integer sz))
= match sz with
| 1 -> parse32_bounded_integer_1
| 2 -> parse32_bounded_integer_2
| 3 -> parse32_bounded_integer_3
| 4 -> parse32_bounded_integer_4
inline_for_extraction
val serialize32_bounded_integer_1
: (serializer32 (serialize_bounded_integer 1))
inline_for_extraction
val serialize32_bounded_integer_2
: (serializer32 (serialize_bounded_integer 2))
inline_for_extraction
val serialize32_bounded_integer_3
: (serializer32 (serialize_bounded_integer 3))
inline_for_extraction
val serialize32_bounded_integer_4
: (serializer32 (serialize_bounded_integer 4))
inline_for_extraction
noextract
let serialize32_bounded_integer
(sz: integer_size)
: Tot (serializer32 (serialize_bounded_integer sz))
= match sz with
| 1 -> serialize32_bounded_integer_1
| 2 -> serialize32_bounded_integer_2
| 3 -> serialize32_bounded_integer_3
| 4 -> serialize32_bounded_integer_4
#push-options "--max_fuel 0"
inline_for_extraction
val parse32_bounded_integer_le_1
: parser32 (parse_bounded_integer_le 1)
inline_for_extraction
val parse32_bounded_integer_le_2
: parser32 (parse_bounded_integer_le 2)
inline_for_extraction
val parse32_bounded_integer_le_3
: parser32 (parse_bounded_integer_le 3)
inline_for_extraction
val parse32_bounded_integer_le_4
: parser32 (parse_bounded_integer_le 4)
inline_for_extraction
noextract
let parse32_bounded_integer_le (sz: integer_size) : Tot (parser32 (parse_bounded_integer_le sz))
= match sz with
| 1 -> parse32_bounded_integer_le_1
| 2 -> parse32_bounded_integer_le_2
| 3 -> parse32_bounded_integer_le_3
| 4 -> parse32_bounded_integer_le_4
inline_for_extraction
val parse32_u16_le : parser32 parse_u16_le
inline_for_extraction
val parse32_u32_le : parser32 parse_u32_le
#pop-options
inline_for_extraction
val serialize32_bounded_integer_le_1 : serializer32 (serialize_bounded_integer_le 1)
inline_for_extraction
val serialize32_bounded_integer_le_2 : serializer32 (serialize_bounded_integer_le 2)
inline_for_extraction
val serialize32_bounded_integer_le_3 : serializer32 (serialize_bounded_integer_le 3)
inline_for_extraction
val serialize32_bounded_integer_le_4 : serializer32 (serialize_bounded_integer_le 4)
inline_for_extraction
noextract
let serialize32_bounded_integer_le (sz: integer_size) : Tot (serializer32 (serialize_bounded_integer_le sz))
= match sz with
| 1 -> serialize32_bounded_integer_le_1
| 2 -> serialize32_bounded_integer_le_2
| 3 -> serialize32_bounded_integer_le_3
| 4 -> serialize32_bounded_integer_le_4
inline_for_extraction
val serialize32_u16_le : serializer32 serialize_u16_le
inline_for_extraction
val serialize32_u32_le : serializer32 serialize_u32_le
inline_for_extraction
let size32_u16_le: size32 serialize_u16_le =
assert_norm (size32_constant_precond serialize_u16_le 2ul);
size32_constant serialize_u16_le 2ul ()
inline_for_extraction
let size32_u32_le: size32 serialize_u32_le =
assert_norm (size32_constant_precond serialize_u32_le 4ul);
size32_constant serialize_u32_le 4ul ()
module U32 = FStar.UInt32
val parse32_bounded_int32_1
(min32: U32.t)
(max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 })
: Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val parse32_bounded_int32_2
(min32: U32.t)
(max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 })
: Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val parse32_bounded_int32_3
(min32: U32.t)
(max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 })
: Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32)))
val parse32_bounded_int32_4
(min32: U32.t)
(max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 })
: Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32)))
inline_for_extraction
let parse32_bounded_int32
(min32: U32.t)
(max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 })
: Tot (parser32 (parse_bounded_int32 (U32.v min32) (U32.v max32)))
= fun input -> (
if max32 `U32.lt` 256ul
then parse32_bounded_int32_1 min32 max32 input
else if max32 `U32.lt` 65536ul
then parse32_bounded_int32_2 min32 max32 input
else if max32 `U32.lt` 16777216ul
then parse32_bounded_int32_3 min32 max32 input
else parse32_bounded_int32_4 min32 max32 input
)
val serialize32_bounded_int32_1
(min32: U32.t)
(max32: U32.t { 0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 256 })
: Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
val serialize32_bounded_int32_2
(min32: U32.t)
(max32: U32.t { 256 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 65536 })
: Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
val serialize32_bounded_int32_3
(min32: U32.t)
(max32: U32.t { 65536 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 16777216 })
: Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32)))
val serialize32_bounded_int32_4
(min32: U32.t)
(max32: U32.t { 16777216 <= U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296 })
: Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32))) | {
"checked_file": "/",
"dependencies": [
"prims.fst.checked",
"LowParse.Spec.BoundedInt.fsti.checked",
"LowParse.SLow.Base.fst.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.SLow.BoundedInt.fsti"
} | [
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": false,
"full_module": "LowParse.SLow.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Spec.BoundedInt",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.SLow",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | false |
min32: FStar.UInt32.t ->
max32:
FStar.UInt32.t
{ 0 < FStar.UInt32.v max32 /\ FStar.UInt32.v min32 <= FStar.UInt32.v max32 /\
FStar.UInt32.v max32 < 4294967296 }
-> LowParse.SLow.Base.serializer32 (LowParse.Spec.BoundedInt.serialize_bounded_int32 (FStar.UInt32.v
min32)
(FStar.UInt32.v max32)) | Prims.Tot | [
"total"
] | [] | [
"FStar.UInt32.t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"FStar.UInt32.v",
"Prims.op_LessThanOrEqual",
"LowParse.Spec.BoundedInt.bounded_int32",
"FStar.UInt32.lt",
"FStar.UInt32.__uint_to_t",
"LowParse.SLow.BoundedInt.serialize32_bounded_int32_1",
"Prims.bool",
"LowParse.SLow.BoundedInt.serialize32_bounded_int32_2",
"LowParse.SLow.BoundedInt.serialize32_bounded_int32_3",
"LowParse.SLow.BoundedInt.serialize32_bounded_int32_4",
"LowParse.SLow.Base.bytes32",
"LowParse.SLow.Base.serializer32_correct",
"LowParse.Spec.BoundedInt.parse_bounded_int32_kind",
"LowParse.Spec.BoundedInt.parse_bounded_int32",
"LowParse.Spec.BoundedInt.serialize_bounded_int32",
"LowParse.SLow.Base.serializer32"
] | [] | false | false | false | false | false | let serialize32_bounded_int32
(min32: U32.t)
(max32: U32.t{0 < U32.v max32 /\ U32.v min32 <= U32.v max32 /\ U32.v max32 < 4294967296})
: Tot (serializer32 (serialize_bounded_int32 (U32.v min32) (U32.v max32))) =
| fun input ->
(if max32 `U32.lt` 256ul
then serialize32_bounded_int32_1 min32 max32 input
else
if max32 `U32.lt` 65536ul
then serialize32_bounded_int32_2 min32 max32 input
else
if max32 `U32.lt` 16777216ul
then serialize32_bounded_int32_3 min32 max32 input
else serialize32_bounded_int32_4 min32 max32 input) | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.